← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #171835]: I need some Variable Help :D

 

Question #171835 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/171835

RaiMan posted a new comment:
You used repair and nextpage as parameter variables too in your
functions. This makes them definitely local, so that changes inside the
function are not reported back to the global context.

Your usage did not make sense anyway: the usage of function parameters
only makes sense, if you want to call the function with different values
for that parameter (take popup() as an example).

an example (I do not know wether this is possible, only the principle)

def findfriendresourcepage(friend):
    click(Pattern(friend).targetOffset(47,-5))
    click(Pattern("rA.png").targetOffset(-1,-46))
    if exists("some-check.png"): return True
    return False

friend1 = "1316552206794.png"
friend2 = "some-other.png"

if findfriendresourcepage(friend1): print "found friend1"

isFriend2 = findfriendresourcepage(friend2)

if isFriend2:
     print "doing something with friend2"
else:
     print "nothing to do"

So we have the possibility, to use the same function with different
values and use the return value, to check/use the result of the
function's internal actions.

So finally: your approach working as expected:

repair = False

def checkforrepair(repair):
    if exists("1316553886107.png"): return True
    return False

repair = checkforrepair(repair)

if repair:
     popup("found a repair btn")
else:
     popup("Didnt find a repair btn")

*** more comments
-- use True and False as booleans not as strings, so they can be used as condition directly (see example above) (as string you need: if repair == "True")
-- better use print for log messages. popup() has to be clicked and so moves the mouse pointer - this might interfere with actions of your script. print works "in the background" and the script runs with the normal speed.

You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.