Skip a chunk of code if img cannot be found

Asked by James

I don't know any Python Coding, so I feel as if I'm dumb for asking this question but here it goes anyway. I have managed to use Sikuli to automate a lot of things so far. I love it, its easy and seems pretty darn stable. My problem is I need a way for Sikuli to look for the image on the screen, if it does not find said image it will skip the chunk of code that pertains to that image and move on to the next image and corresponding chunk of code for it. Is there an easy way to do this without having to take a crash course in Python?? or do I need to use Python in order to achieve this?? Thanks in advance for your answers.

James.

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
James (crash195x2) said :
#1

x = (img)
if
x = (img)
else
#Chunk of code
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
if
x = ()
else
#Next img and chunk of code
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>

Is that even close??? LOL

Revision history for this message
James (crash195x2) said :
#2

ah would most likely be more like
x = (img)
if x= img
>>>>>>
>>>>>> #chunk of code for X
>>>>>>

Else
>>>>>>
>>>>>> #new img and chunk of code.
>>>>>>

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

only a few things:
- one line --- one command
- if, elsif, else, while have to be written as if condition: (colon at end)
- chunk of code (block), that belongs to an if e.g. has to be indented (best practice: always use 3 blanks, don't tab!)
- next statement after an block: reduce indentation to what outer block has
- you can use variables for everything, to save it for future use
- a one line comment goes after #

example: (mind indentation, the oddest thing with python (you don't have a block-end!))
I use variables for everything here.

img = <image> # to be captured
found = find(img) # True if found, False otherwise
if found: # shorty for if found == True: or if not found == False: (thats really odd)
   msg = "found! What now?"
   backMsg = input(msg) # ask user for some input, None if user clicks only ok, otherwise text
   if not backMsg: # is None is False if user clicks only OK
      popup("OK, you are fed up")
      backMsg = "" # so we later know we have to finish
   else:
      popup("Yes, we go on!") # this is the last statement of the else: AND the outer if found:
else:
   popup("Sorry, not found")
   backMsg = ""
if not backMsg == "": # we have to goon
   >>>> # this indented code only runs, if found AND user said something
   >>>>
   >>>>
popup("this is the end!")

hope it helps.

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

add on!

due to odd comment formatting (new line before found:) it reads in the middle:
      popup("Yes, we go on!") # this is the last statement of the else: AND the outer if
found:

should read:
      popup("Yes, we go on!") # the last statement of else: AND of the outer if found:

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

if you look at some of my answers, bugreports and comments (click Raiman and Answers, Bugs on my personal page) you may find some other hints.

I know how to program, but touched python with Sikuli first time. So we are in one boat ;-)

Can you help with this problem?

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

To post a message you must log in.