Reputation: 3
when my code exits this while loop and if statement :
if im.getpixel((258,375)) == (30,37,43):
battle = True
print('lets Battle!!')
time.sleep(10)
leftClick()
while battle == True:
mousePos(503,487)
leftClick()
leftClick()
time.sleep(5)
im = screenGrab()
if im.getpixel((258,375)) != (30,37,43) and im.getpixel((258,375)) != (99, 114, 121) and im.getpixel((258,375)) != (225, 225, 225):
battle = False
break
print('battle Over')
break
The code ends the parent while loop:
while 1 == 1:
im = screenGrab()
if im.getpixel((258,375)) == (30,37,43):
battle = True
print('lets Battle!!')
time.sleep(10)
leftClick()
while battle == True:
mousePos(503,487)
leftClick()
leftClick()
time.sleep(5)
im = screenGrab()
if im.getpixel((258,375)) != (30,37,43) and im.getpixel((258,375)) != (99, 114, 121) and im.getpixel((258,375)) != (225, 225, 225):
battle = False
break
print('battle Over')
break
left(2)
right(2)
I have been trying for ages but I can't get left() and right() to run and the loop to continue after the if statement ends.
Thanks for your help.
Upvotes: 0
Views: 934
Reputation: 324
Break exits the current loop(while or for) not 'if' or 'else'. Use 'continue' to break the current iteration. And your code has 2 breaks remove the outer break and it should work as expected.
Upvotes: 0
Reputation: 8686
You are calling break
after your print
statement :
print('battle Over')
break
Your first break
statement exits the second while
and the break
mentioned above exits your first while
.
Simply remove the break
statement if you do not want to exit the parent while
after the if
statement.
Upvotes: 1