Last click refuses to work

Asked by jeff

I have a relatively simple script, its for a game. It clicks each button right when it pops up way until the very end. Here is the script

while 1 < 2: # Neverending loop
 click( image1 )
 click( image2 )
 click( image3 )
 click( image4 )
 click( image5 )
 click( image6 )

 observe(4) # wait for load

 while exists( image7 ): # while image7 is in place, the click below will continue clicking the same image over and over.
  click( image 8 ) This park works fine
  observe(1)

click( image9 ) <-- The problem. This image will click an image of the word "Finished" when the while turns false for image7. No matter what I do, I cannot get it to click at all, which ends up terminating the script. Its suppose to click Finished,
then start from the beginning at image1.

observe(5)

Any ideas?

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

I collected the scripting statements and made some "optimizations"
--- never ending loop: while True:
--- just wait some seconds: wait() instead of observe()
--- using exists( ... , 0) (only one search, do not wait 3 seconds) in while loops with own timing using wait

while True: # Neverending loop
 click( image1 )
 click( image2 )
 click( image3 )
 click( image4 )
 click( image5 )
 click( image6 )
 wait(4) # wait for load

 while exists( image7, 0 ): # while image7 is in place,
  click( image 8 )
  wait(1)

click( image9 ) # <-- The problem.

wait(5)

-- your question:
It is always a problem here, to recognize indentation, but your click( image9 ) seems to be on the same indent level as the first while, and hence outside the loop. So after image7 vanishes, the loop starts all over again, but should stop with a FindFailed, if I understand the intended workflow right (image9 has to be clicked before starting all over again).

If I understand you right, this is what you want:

I put the indentation levels as comments like # +1, where the number means the number of indent tabs in the IDE

while True: # Neverending loop
# +1
 click( image1 )
 click( image2 )
 click( image3 )
 click( image4 )
 click( image5 )
 click( image6 )
 wait(4) # wait for load

 while exists( image7, 0 ): # while image7 is in place,
# +2
  click( image 8 )
  wait(1)

# +1
 click( image9 ) # <-- The problem.
 wait(5)

# +0
print "outside loop"

the print statement will never be executed, since your while True: loop does not contain any code to end the loop (e.g. a break to jump out of the loop or an exit() to gracefully end the script) (see FAQ 1437)

Revision history for this message
jeff (jbrown49) said :
#2

<a target='_blank' title='ImageShack - Image And Video Hosting' href='http://img199.imageshack.us/i/63805296.png/'><img src='http://img199.imageshack.us/img199/1729/63805296.png' border='0'/></a>

I'm still getting the same error :(

Here is the error:

[sikuli] Stopped
[sikuli] An error occurs at line 13
[sikuli] Error message:
Traceback (most recent call last):
  File "C:\Users\Name\AppData\Local\Temp\sikuli-tmp16417.py", line 13, in <module>
    click("1296886298136.png")
  File "C:\Users\Name\Desktop\Sikuli-IDE\sikuli-script.jar\Lib\sikuli\Region.py", line 119, in click
  Line 20, in file C:\Users\Name\AppData\Local\Temp\sikuli-tmp16417.py

 at edu.mit.csail.uid.Region.wait(Region.java:240)

 at org.python.proxies.sikuli.Region$Region$1.super__wait(Unknown Source)

 at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

 at java.lang.reflect.Method.invoke(Unknown Source)

edu.mit.csail.uid.FindFailed: FindFailed: 1296886298136.png can't be found.
  Line 20, in file C:\Users\Name\AppData\Local\Temp\sikuli-tmp16417.py

Revision history for this message
jeff (jbrown49) said :
#3

Got it to work, turned the similarity of the last image down to .55 and it recognizes it now perfectly. Not sure why it didn't before.

Thanks for the help.

Revision history for this message
jeff (jbrown49) said :
#4

Thanks RaiMan, that solved my question.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

If you need to reduce the similarity below the standard of 0.7, to make the find successful, this is a hint, that your image does not contain enough characteristic elements (too small, only text, ...). The lower the selected minimum similarity, the higher the risk, that something else is found, that matches.

The better solution usually is, to re-capture the image with a larger area around it or to restrict the region to the area, where the image should be found.