0
a = 0
b = 0

def check():
    if (pya.locateOnScreen("image.PNG") != None):
        print("Found")
        a = 1
    else:
        print("Not found")
        b = 1

check()
print(a,b)

Output is:

Found
0 0

Even though it finds the image, it doesn't change the value of a.

I think the output should be:

Found
1 0

What I am doing wrong?

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
Boranroni
  • 1
  • 1
  • a is creating a local variable in the function, and not referring to the global variable a. – Albin Paul Sep 01 '21 at 15:22
  • `a` and `b` are local to the scope of `check()`. If you want to use them outside that scope, you can return them or (less preferred) set them as global variables. – NGilbert Sep 01 '21 at 15:23

0 Answers0