Sikuli is stuck finding one image that no longer exists

Asked by Deses

Hello, I've bump into a problem trying to make some scripts...

I have my problem in the first while loop, it works well but when the image disappears, the loop still finds it, getting stuck there.

I'm aware that waitVanish is what I need, but that simply doesn't work, after around 20 seconds the waitVanish ends although the image is still present, no matter how many seconds I pass to the second variable... :(

Maybe the problem is about the flow of the program, because it has been a long time since I touched code... I don't know.

Here is the code, I've put some popups to see the flow:

def estoyListo():
 if exists(img_readyNow):
  popup("img_readyNow")
  click(img_readyNow)
 while exists(img_dontPanic):
  popup("img_dontPanic")
  pass
 if exists(img_repairDamage):
  popup("img_repairDamage")
  click(img_repairDamage)
 while exists(img_close):
  popup("img_close")
  click(img_close)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

--1. debugging
to debug such problems, it is better to either use highlight(), to see, what Sikuli finds.

--2. waitVanish()
is nothing better, than while exists(), but even more flexible ;-)

This would be my script variant

def estoyListo():
    if exists(img_readyNow):
        click(getLastMatch())
    while exists(img_dontPanic):
        getLastMatch().highlight(2) # for debugging only
        wait(1)
    if exists(img_repairDamage):
        click(getLastMatch())
    while exists(img_close):
        click(getLastMatch())
        wait(1)

So you now cans see, what Sikuli "thinks" dontPanic might be on your screen.
If it is a false positive, you might either:
- make a better screenshot (minimum background)
- restrict the search region ( some-Region.exists() )
- raise the similarity ( exists(Pattern(img_repairDamage).similar(0.95)) )

BTW: The last loop does not really make sense, since it clicks as long as the image is visible. Usually one click is enough.

Revision history for this message
Deses (deses12) said :
#2

Thank you for the response. I'm going to try your variant and see if I can't debug everything with highlight... thats a nifty method, I'm sure I'm going to use it a lot. :D

And that last loop does make sense, because it could appear more than once. The game makes me close a lot of popups. :P

Revision history for this message
Deses (deses12) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
Deses (deses12) said :
#4

Yep, that torally was it. Using highlight it was outlining a totally random area, that was not showing in the patterm settings.

Thanks a lot RainMan!