multiple statements?

Asked by Smythe Winsington

is it possible in Sikuli to have multiple classes in a single script file?

What I'm trying to do now is basically look for one of a series of images and based on that image execute a command

that part is easy to do but what I'm having trouble doing is the next part

after I have executed the command I would like to look for the remaining images, and if they aren't found just keep looking until one is found and then execute a separate command based on it and so on

what I was trying to do was something like this:

A = imageA
B = imageB
C = imageC

match1 = False
match2 = False
match3 = False

while not match1 or match2 or match3:
     if find(imageA):
          case = 1
     elif find(imageB):
          case = 2
     elif find(imageC):
          case = 3
     else continue

if case == 1:
     popup("Match 1 found")
     match1 = True
if case == 2:
     popup("Match 2 found")
     match2 = True
if case == 3:
     popup("Match 3 found")
     match3 = True

while match1:
     if find(imageB):
          case = 2
     elif find(imageC):
          case = 3
     else continue

while match2:
     if find(imageA):
          case = 1
     elif find(imageC):
          case = 3
     else continue

while match3:
     if find(imageA):
          case = 1
     elif find(imageB):
          case = 2
     else continue

I'm also having trouble searching within a region, all of the images appear within a different part of the screen so I was thinking about setting a match as a variable where m1 = (roiImage).inside().find(image1) and so on, but I can't seem to get that to work either

Any idea where I should start looking?

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
Tsung-Hsiang Chang (vgod) said :
#1

You may want to take a look at http://sikuli.org/trac/wiki/reference-0.10#ObservingVisualEventsinaRegion.
You can observe multiple visual events at the same time and do more things in each handler.

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

1. Using find() in an IF, will not work as expected, since a not found situation (where you expect the else branch to be executed) will stop the script with a FindFailed exception. So you never get to the elif's or else's

2. your first while: would never end, since the condition is always true (match1, ..2, ..3 do not change in the loop).

3. m1 = (roiImage).inside().find(image1): (roiImage) must be a region (e.g. upper left part of screen). An image as such does not know its "region". If your image is only existing once on the screen, you can simply use find(image) - no need to specify a region. Otherwise you have to use selectRegion() (interactive) or evaluate the needed region somehow differently.

4. Tsung-Hsiang Chan is right in talking about observing. This is the best approach theoretically, but there are some pitfalls and still some bugs. I tried an example that might be as complex as yours, but in the end I returned to exists() and expecting the app to be in a specific state.

Can you help with this problem?

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

To post a message you must log in.