[英]How can I run a while loop in the background so that the other operations can continue (Python)
I am making a simple game, and have created a loop to continuously check if the enemy is dead:我正在制作一个简单的游戏,并创建了一个循环来不断检查敌人是否已经死亡:
while player_health > 0:
if current_enemy_dic['current_enemy']['Health'] <= 0:
slayed_enemy_count = slayed_enemy_count + 1
enemy_encounter(slayed_enemy_count)
The problem is that the program will not allow the other code to run, and will continually be checking for the if statement to be true.问题是程序不允许其他代码运行,并且会不断检查 if 语句是否为真。 To fix this, I was wondering if there was a way for it to run in the background, and run concurrently with other operations.为了解决这个问题,我想知道是否有办法让它在后台运行,并与其他操作同时运行。
Thank you谢谢
Don't do it concurrently: Create a main loop, register various tasks with the loop.不要同时进行:创建一个主循环,在循环中注册各种任务。 Every time around the loop the tasks will run.每次循环时,任务都会运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.