[英]PIL.ImageGrab , grab() and load() functions in thread
I want to create a game bot but with threading.我想创建一个带有线程的游戏机器人。
When script founds game screen works 1 time and stop with this message "Process finished with exit code 0".当脚本发现游戏屏幕工作 1 次并停止并显示此消息“进程已完成,退出代码为 0”。 But scrpit can not found the game screen, works truly...
但是scrpit找不到游戏画面,确实有效...
How can I fix this problem?我该如何解决这个问题? Thanks a lot.
非常感谢。
class POT(Thread):
global x, y
def __init__(self):
Thread.__init__(self)
self.running = True
def run(self):
while self.running:
try:
x, y = locateCenterOnScreen('menu.PNG')
text = grab().load()[x - 670, y - 730]
text2 = grab().load()[x - 757, y - 730]
if (text[0] < 150):
for z in range(3):
press('0')
sleep(0.05)
release('0')
sleep(0.05)
print('HP USED')
if text2[0] < 150:
for z in range(3):
press('6')
sleep(0.025)
release('6')
sleep(0.025)
press('5')
sleep(0.033)
release('5')
sleep(0.033)
print('INTUITION USED 6')
print('AURA USED 5')
print(x, y)
return x, y
except:
print("GAME SCREEN NOT FOUND...")
bot=POT()
bot.start()
bot.join()
You're doing return x, y
.你正在做
return x, y
。
That will break the while self.running
loop, so the thread ends, and with it, your program.这将打破
while self.running
循环,因此线程结束,您的程序也随之结束。
As an aside:作为旁白:
try: except:
block.try: except:
块。 It will also catch SystemExit
s and KeyboardInterrupt
s.SystemExit
和KeyboardInterrupt
。
try: except Exception:
instead of try: except:
, you'd want to use traceback.print_exc()
so you know the actual exception.try: except Exception:
而不是try: except:
,你会想要使用traceback.print_exc()
来了解实际的异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.