Restart Script [Redirect/Loop to Beginning] in Sikuli
Just wanted to point out an awesome function for restarting your script, or looping back to the beginning of the script in Sikuli. For those of you who don’t know what Sikuli is, check out my post here. The code for looping to the beginning is dead simple, but it took some digging to get to it. The code is:
continue
That’s it! Here’s an example script using the ‘continue’ tag:
setThrowException(False)
if find (IMG):
popup("Found")
continue
else:
popup("Not Found")
wait(IMG)
click(IMG)
popup("End of Script")
if find (IMG):
popup("Found")
continue
else:
popup("Not Found")
wait(IMG)
click(IMG)
popup("End of Script")
This can also be used to loop a script, like in the example below:
setThrowException(False)
if find (IMG):
popup("Found")
continue
else:
popup("Not Found")
wait(IMG)
click(IMG)
popup("Script will now loop.")
continue
if find (IMG):
popup("Found")
continue
else:
popup("Not Found")
wait(IMG)
click(IMG)
popup("Script will now loop.")
continue
Tada! You’ve now looped a script in Sikuli.