How to use getLastMatch

Asked by kaefert

I wanted to click something that I first found with an exist. according to how I understood the docs from here:
http://doc.sikuli.org/region.html#Region.getLastMatch

that should work quite simply by calling
click(Region.getLastMatch())

but that throws me this error with Sikuli 1.0.1:
Unexpected error: <type 'exceptions.TypeError'> ; getLastMatch(): expected 1 args; got 0

whats the (undocumented?) argument that sikuli expects?

Question information

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

all documented Region functions are object methods and hence have to be used with a Region OBJECT and not with the Region CLASS (as you did with Region. )

The respective region is the region, where the respective search was done.
If you did an undotted search (something like exists(some_image) then the respective region is the whole screen, that automagically behind the scenes leads to SCREEN.exists(some_image). Where SCREEN is a "constant" region object created as Screen(0).

hence in your case:
if exists(some_button):
    click(getLastMatch())

or with a specified region
reg = <some evaluated region>
if reg.exists(some_button):
    click(reg.getLastMatch())

since 1.0.1 there is a convenience available (not yet documented):
if exists(some_button):
    click()

or with a specified region
reg = <some evaluated region>
if reg.exists(some_button):
    reg.click()

a click or similar functions without parameters will click the last match of that region or the center if no match exists yet.

Revision history for this message
kaefert (kaefert) said :
#2

Thanks RaiMan, that solved my question.