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". But scrpit can not found the game screen, works truly...
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()
CodePudding user response:
You're doing return x, y
.
That will break the while self.running
loop, so the thread ends, and with it, your program.
As an aside:
- you don't need a thread for this since your program is doing nothing else than this loop.
- you should never, ever use a bare
try: except:
block. It will also catchSystemExit
s andKeyboardInterrupt
s.- If you'd use
try: except Exception:
instead oftry: except:
, you'd want to usetraceback.print_exc()
so you know the actual exception.
- If you'd use