← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #634207]: Change variable in onChange

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
variables being assigned a value are taken as local to the def context
and hence not "known" in the main context.

try this:
def changed(event):
    global restart
    restart=True

global makes the given variable name also known in the top-level outside
context.

Another comment:
I do not know the timing of your app context:
Be aware: the observation does not stop, but continouosly runs in the background.
So some coordination might be needed between foreground and background.

So you might generally stop the observation in the handler and restart it at the end of the while loop or wherever it makes sense.
So my version:

def changed(event):
    event.stopObserver()
    restart=True

restart=False
region.onChange(100, changed)
region.observe(background=True)

while True:
    if restart:
        #do stuff
    else:
        #do other stuff
    restart = False
    region.observe(background=True)

other valuable options with 1.1.1+ can be found in the docs:
http://sikulix-2014.readthedocs.io/en/latest/region.html#observing-visual-events-in-a-region

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.