【发布时间】:2021-10-08 23:17:54
【问题描述】:
您好,提前谢谢您。我编写了一个脚本,却发现它有一个重大缺陷。
在BUTTON#8 下面的这段代码中调用了调度。效果很好,直到我多次按下BUTTON#8。
game_state = True
run = True
while run:
for event in pygame.event.get():
if event.type == JOYBUTTONDOWN:
print(event)
if event.button == 8:
if game_state == True:
schedule.every(3).seconds.until(timedelta(minutes=60)).do(sendCommands)
else:
game_state = True # schedule on
if event.type == JOYHATMOTION:
if event.value[1] == 1:
game_state = False
if event.value[1] == -1:
game_state = False
if event.type == JOYBUTTONDOWN:
if event.button == 4:
game_state = False
if game_state == True:
schedule.run_pending()
pygame.quit()
sys.exit()
我希望JOYBUTTON#8 只调用一次时间表,直到game_state = False 再调用一次。我注意到,如果我不小心多次按下按钮,调度会被多次调用,一次运行多个实例。如何防止多个实例同时运行?
有没有办法,一旦我按下BUTTON#8,禁用它直到我按下JOYHATMOTION或BUTTON#4?
【问题讨论】:
标签: python python-3.x pygame scheduled-tasks schedule