Giving me an error in a if

Asked by Clonex

Hello there,
I'm getting an error in my code, and I cant find the error.
I dont have much experience with Sikuli, so please bare with me.

Heres an image of the code:
http://i54.tinypic.com/av0oj7.png

And, a copy og the code:
while true:
 im = find( )
 if im:
  thex = im.getX()
  t1 = Match(thex, im.getY() + 35, im.getW(), im.getH(), 1)
  click(t1)
 else:
  if find( ):
   #WAITING
  else:
   if find( ):
    click( )
   else:
    exit()

Hoping someone can help me.
Thanks.

Question information

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

what kind of error? hard to guess ;-)

one thing:

  t1 = Match(thex, im.getY() + 35, im.getW(), im.getH(), 1)
  click(t1)

A Match should not be created by hand (it is returned by a find). A Match is a rectangular object and inherits from Region.

so you should do this, to get a "handmade" Region object:
  t1 = Region(thex, im.getY() + 35, im.getW(), im.getH())

But in this case this is not needed:
Since a click on a Region clicks on the center and you are placing the region to click 35 pixels downwards, the easiest possibility (among many others ;-)

if im:
    click(im.getCenter().below(35))
else:
....

One more thing:
if find():

does not make sense, since if not found the script will stop with a FindFailed error.

In these cases you have to use exists()

if exists("some-image.png"):
    click(getLastMatch()) # would click the found image
else:
    print "not found"; exit(1)

To learn about the used features: http://sikuli.org/docx/

Revision history for this message
Clonex (clonex-kontakt) said :
#2

Thanks helped me alot.
I'm getting an error on line 10 (Take a look at the image I've posted)

I've updated the code from the help you gave me:
while true:
 im = find( )
 if exists(getLastMatch()):
  click(im.getCenter().below(35))
 else:
  if exists( ):
   #WAITING
  else:
   if exists( ):
    click( )
   else:
    exit(1)

It's giving me the error on line 8, at:
  if exists( ):
   #WAITING
  else: <-- ERROR

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

That is always a problem here, since you do not see the real script.

Tip: when asking, it is helpful to have the error message from the IDE's message area pasted here (only the part with the line number and the error text).

In this case I can guess again:

  if exists( ):
   #WAITING
  else:

you get an error telling something about bad indentation.
If something, that has to be indented, does not have some code yet, at least a "pass" is needed (a real statement, does nothing but having the correct indentation) a comment is simply ignored for this purpose.

so:

  if exists( ):
   pass #WAITING
  else:

should help.

Can you help with this problem?

Provide an answer of your own, or ask Clonex for more information if necessary.

To post a message you must log in.