match() if not found what value does it give?

Asked by MP

In the code below I am learning the basics. But I cant seem to give a "not found" popup when he didnt find the image.

1) what is wrong in the code to give a not found popup?
2) what is the value the find gives if he doesnt find anything?

code:
===========================
m = find("IMAGE")
if m.exists:

    popup ("FOUND")
    m.highlight()
    wait (2)
    m.highlight()
    print ("FOUND")

else:

    popup ("NOT FOUND")
===========================

thx :)

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

From where did you get the impression, that m.exists is the way to find out, wether the image was found before?
So please read the docs about the features and functions, before digging around.

BTW:
    m.highlight()
    wait (2)
    m.highlight()

is the same as
m.highlight(2) # see docs

and if you use the highlight feature, you do not need any other feedback like popups and prints.

The reason behind the trap into that you ran is very technical:
- the find op returns a Match object, which is the region the image occupies on the screen
- find throws FindFailed if not found (so your script should crash anyways if not found)
- m.exists is always True, because it is a function in the Match/Region class (so the else branch would never be executed anyways)

Revision history for this message
MP (jozzzzzz) said :
#2

Thanks RaiMan, that solved my question.