if find or if exists SyntaxError

Asked by charliedaps on 2018-11-30

Hello everyone,

I can not find the solution for image search with an IF

The goal is that the action continues if the image is found and the action closes the window if the image is not found.

So I have

if find (image):
rightclick(image)
click(image2)
.......
else:
type(Key.F4, KEY_CTRL)

And here is the error indicated by sikulixide

SuntaxError ("mismatched imput "rightclick expecting indent",)
Error on the line rightclick(image)

I try with if exists(image): (same error)

Thank you in advance for your help.

Have a good day

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-11-30
Last reply:
2018-11-30
masuo (masuo-ohara) said : #1

indentation means that a space at the beginning of a line of writing.

[error example]
if find (image):
rightclick(image)

[correct example]
if find (image):
    rightclick(image)

masuo (masuo-ohara) said : #2

It is not a problem of SikuliX.
You have to learn Python's grammar.

charliedaps (charliedaps) said : #3

Thanks a lot for your answer.

Yes, I do not have an error message anymore but the "else" does not work.

I watched a little tutorial on the python language and I do not see where my mistake is.

Thank you for your help.

click(Location(375,12))

if find("1543482223289.png"):
    rightClick("1543482245544.png")
    click("1543482269376.png")
    type(Key.F4, KEY_CTRL)
    find("1543482297701.png")
    click("1543482306133.png")
    type(Key.ENTER)
    type("v", KeyModifier.CTRL)
else:
    type(Key.F4, KEY_CTRL)

masuo (masuo-ohara) said : #4

"does not work" mean FinFailed error?

read docs
https://sikulix-2014.readthedocs.io/en/latest/region.html?#exception-findfailed

use exists() instead of find()

charliedaps (charliedaps) said : #6

Thanks masuo.

Exists forks fine. I understend now the difference between exists and find ;)

Another question about the loop.

I would like this code to be executed 3 times and then the rest of the script continues.

I found some examples with print but I do not understand how to apply it to my code.

thank you in advance

masuo (masuo-ohara) said : #7

It is not a problem of SikuliX.
Now you have understood SikuliX.
Next you have to learn Python's grammar.

Manfred Hampl (m-hampl) said : #8

Manfred Hampl suggests this article as an answer to your question:
FAQ #1437: “[HowTo] repeat something in a Sikuli script (make loops)”.

Can you help with this problem?

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

To post a message you must log in.