Using multiple screenshots inside exists()

Asked by Benjamin Alijagić

So I have two samples of buttons that might show up and I need a way to put them inside a exists(). Something like exists(screenshot1 or screenshot2) but that is of course not working.

Anyone?

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
Benjamin Alijagić (madebybenjamin) said :
#1

One more question...
The script I'm trying to build is something like a little farmer bot, so it click on some wheat, then clicks on "reap" button and repeats that action. What would be the easiest way to take current mouse position (or position of the last click on "reap" button) and to find closest available wheat target next to this current?

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

--- first question

which = None
while True:
    if exists(button1, 0):
        which = "button1"
        break
    if exists(button2, 0):
        which = "button2"
        break
    wait(1)
if which == "button1":
    print "Found Button 1"
elif which == "button2":
    print "Found Button 2"
else:
    print "should never happen ;-)"

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

--- second question

lastClick = getLastMatch() # center of last clicked/found image
current = Region(lastClick.x, lastClick.y, 1, 1) # where we want to look around
nearest = current.nearby(100).find(wheat)

Revision history for this message
Albert (alberttarcy) said :
#4

nearest = current.nearby(100).find(wheat)

Can you explain that syntax to me please?

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

@ Albert
see docs: http://sikuli.org/docx/region.html#extending-a-region

BTW: Just found, the above snippet uses upper left corner of last match.
if you want to use center:

LastClick = getLastMatch().getCenter() # center of last clicked/found image
current = Region(lastClick.x, lastClick.y, 1, 1) # where we want to look around
nearest = current.nearby(100).find(wheat)

Revision history for this message
Sami Keränen (sami-keranen) said :
#6

Hi,
First post ever. But related to the first one. I have used following syntax when there is multiple images to use and there is no need for infinite waiting:

if exists(image1, 0) or exists(image2, 0):
    click(getLastMatch())
else:
    # Do something if images not found

Can you help with this problem?

Provide an answer of your own, or ask Benjamin Alijagić for more information if necessary.

To post a message you must log in.