← Back to team overview

sikuli-driver team mailing list archive

[Question #660366]: How to continously run a piece of code while simultaneously checking for a condition?

 

New question #660366 on Sikuli:
https://answers.launchpad.net/sikuli/+question/660366

Hi. How can you make Sikuli check if a statement / condition is being fulfilled while simultaneously executing another piece of code?

What I'm trying to achieve:
* While there isn't an image in a region, keep running a piece of code
* If the image appears (while running the code), stop running piece of code

Lacking approach:

Settings.WaitScanRate = 0.25
someRegion = Region(x1, y1, x2, y2)
someImage = "image.png"

def danceLeft():   #Just some functions
def danceRight():
def danceAcrossTheHallway():

someCondition = None
while someCondition == None:
    danceLeft()
    danceRight()
    danceAcrossTheHallway()
    someCondition = someRegion.exists(someImg, 1)
else:
   print("Stopped dancing; the image has appeared!")


The problem is obvious - the script won't check the condition until it reaches the very last line in the while loop, and while it will be checking, the next iteration of the loop will be held on pause. How can this be avoided? I want it run a while loop without any interruptions while checking for a condition meanwhile, and stop the loop while the condition (an image appearing in a region, in this case) is met.
My hobby-level programming skills have so far mostly consisted of solving everything by doing silly loops, but something tells me there must be a better way. Cheers for the wonderful piece of software that is Sikuli; it's really amazing! Cheers. :D

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