How to repeat action unitil an image appears and then resume script?

Asked by Kevin

I have a script that loops forever. I'd like to add a section that will press the right arrow key until an image appears. Once it appears then return to the regular script. i'm new to sikuli so any help on how to do this would be great! thanks =)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Kevin
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Eugene S (shragovich) said :
#1

You can just add and "if exists(image)" clause at some point of your loop to check whether this image exists.
If yes - press the button, if not - just continue.

the code will look something like that:

while True: #Main loop
  if exists(image): # Each time check for the image
    type(Key.RIGHT)

Revision history for this message
Kevin (kevinesteban) said :
#2

Great! that really cleared up some confusion I had about the script.
Thanks a lot!! =)

Revision history for this message
Kevin (kevinesteban) said :
#4

I'm still having a bit of a problem actually.
I want it to keep pressing RIGHT until the image appears and then to click the image and go back into the loop.

The following script only presses the arrow button once and then moves onto the "else" part

while True:

(MAIN SCRIPT PRESENT)

if not Region().exists(.png):
       type(Key.RIGHT)

else:
click(.png)

(repeat script)

Revision history for this message
Kevin (kevinesteban) said :
#5

whoops.. i should be using while instead of if.. thanks ;)