#πŸ”’ pyautogui IF

38 messages Β· Page 1 of 1 (latest)

tacit ivy
#

Hi i cant get my code to work for making a if statement
It just keeps doing the same line for code even those the image there is changed 100% in the image

cast = pyautogui.screenshot('FishingRod.png',region=(465, 26, 901, 102
while startfishing == True:
time.sleep(1)
if pyautogui.locateOnScreen('FishingRod.png', confidence=0.100) is None:
print("Fishing Rod Detected, reeling in")

    else:
        cast = pyautogui.screenshot('FishingRod.png',region=(465, 26, 901, 102)) 
        print("Fishing Rod Not Detected, waiting")
covert boughBOT
#

@tacit ivy

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

spice turtle
#

Does anything get printed?

tacit ivy
#

a whole load of Fishing Rod Not Detected, waiting

#

even when i changed my screen around thats all it says

grizzled barn
#

the if isn't broken, so you're getting a None from your locateOnScreen call

tacit ivy
#

yes im not getting a none from the locate

grizzled barn
#

you are

#

oh sorry, misread, righ tyou are

#

oh wait

#

you have your condition backwards then...you want to fall into the if branch when you do locate the image, right?

tacit ivy
#

no i think i have thoses correct its when the screen shot isnt on the screen

#

when the screen shot and my screen miss match

grizzled barn
#

what do you want to be printed when the screenshot is on the screen?

tacit ivy
#

it goes to the else:

grizzled barn
#

and actually, I think it's always going to be true because you're storing your screenshot in FishingRod.png, then checking if FishingRod.png is in the screenshot...which it of course is

tacit ivy
#

yes so it goes to else

grizzled barn
#

right, and it always will

#

because you're saying "take a screenshot. is that screenshot in the screenshot?"

tacit ivy
#

theres a time.sleep(1) in the while
as the else is instant

#

even if i take it out it still does the same thing

grizzled barn
#

that doesn't change what I just said

#

what does this do: pyautogui.screenshot('FishingRod.png',region=(465, 26, 901, 102))

#

that takes a screenshot and saves it in FishingRod.png, right?

tacit ivy
#

yes

#

i didnt put all of the code there theres a time.sleep(5) after the print("Fishing Rod Not Detected, waiting")

grizzled barn
#

right, that doesn't change it

#

here's what you're doing:

  • take a screenshot and store it in file.png
  • hey, does file.png appear on the screen?
#

of course it appears on the screen, it's a screenshot of the screen

tacit ivy
#

the screen changes tho its not a static thing

tacit ivy
#

im i just not getting this correct

grizzled barn
#

right, that's the point, you always capture another screenshot

#

and then check for that screenshot

tacit ivy
covert boughBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.