else if

Asked by Llewelyn Mc Carthy

Hi,

I tried now for some time to build a python else if structure like this:
---------------------------------------------------------------------------------------------
if exists(img01):
  ...
elif exists(img02):
  ...
elif exists(img03):
---------------------------------------------------------------------------------------------
This is common python syntax but it does not work. If I structure it like this:
---------------------------------------------------------------------------------------------
if exists(img01):
  ...
if exists(img02):
  ...
if exists(img03):
---------------------------------------------------------------------------------------------
Not all cases are triggered when the images appear. I only want one "if" and "else ifs" if possible. Only "else" is not specific enough because I want a restraint from the existing picture. Anyone know how to build this?

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

That is tricky with Sikuli, since each exists() makes a find operation that lasts 3 seconds if not found.

So if you want to check "concurrently" for more than one image, you have to use observe() (rather complex) or a loop with exists(img,0) (searches only one time) which I usually prefer.

i1 = i2 = i3 = False
while True:
   if exists(img1, 0): i1 = True
   if exists(img2, 0): i2 = True
   if exists(img3, 0): i3 = True
   if i1 or i2 or i3: break
   wait(1)
# now you can make your decisions based on i1, i2 and i3

Revision history for this message
Llewelyn Mc Carthy (dummy-d) said :
#2

I will use observe() because img2 are actually three images

Can you help with this problem?

Provide an answer of your own, or ask Llewelyn Mc Carthy for more information if necessary.

To post a message you must log in.