Loop is not working (while, if)

Asked by Ricardo Luzini

Hi guys,
 I'm sure that something trivial like this will make you laugh, but I cannot fix it, even trying for hours:

In this spcipt, the execution stops with this error message:
"[error] script [ 000_ArtWar ] stopped with error in line 13 at column 4
[error] SyntaxError ( "no viable alternative at input 'exists'", )"

This is the script:

Settings.MoveMouseDelay = 0.0
andAndo = True

def runHotkey(event):
 global andando
 andando = False

Env.addHotkey(Key.F1, KeyModifier.CTRL, runHotkey)
war = switchApp("Moto G_Play")

while(war.hasWindow() and andAndo and brigar <> 5):
#for brigar in range(2): #roda 2 vezes
 If exists("enon.png"): #ERROR MESSAGE POINTS TO HERE
  click("Toran.png".similar(0.90)
 wait("Batalhar-1.png",50)
 click("Batalhar-2.png")
 wait("tien.png",50)
 click("tien.png")
 If brigar = 3
  wait(Pattern("1627992723202.png").targetOffset(58,171),30)
  click(Pattern("1627992723202.png").targetOffset(57,162))
  wait("Goletar.png",50)
  click("Goletar.png")
 brigar += 1

I've tried to change "exists" for "find", but I got same error.
Any tip or clue?

Question information

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

Nothing to laugh ---- Python Syntax error messages are sometimes not really helpful.
In many cases the real problem is in the next line.
The error message itself points to the place, where the interpreter gave up, telling, that this was the last stuff it understood.

click("Toran.png".similar(0.90)

... at least a closing bracket is missing:

click("Toran.png".similar(0.90))
... but this would lead to a runtime problem, because String does not have a method similar().

click(Pattern("Toran.png").similar(0.90))

should work.

Revision history for this message
Ricardo Luzini (rluzini) said :
#2

Hi RaiMan, thanks for you quick answer.

I tried the suggested solution, but I got the same error message. I also tried "without Pattern" in the lines, just fixing the brackets.

while(war.hasWindow() and andAndo and brigar <> 5):
 If exists(Pattern("enon.png")):
  click(Pattern("Toran.png".similar(0.90))
 wait("Batalhar-1.png",50)
 click("Batalhar-2.png")
 If exists("enon.png"): #check erro rede
  click(Pattern("Toran.png").similar(0.90))
 wait(Pattern("be.png").targetOffset(133,-8),50)
 click(Pattern("be.png").targetOffset(133,-8))
 If exists("enon.png"): #check erro rede
  click(Pattern("Toran.png").similar(0.90))
 wait("tien.png",50)

Revision history for this message
Manfred Hampl (m-hampl) said :
#3

Please compare
click(Pattern("Toran.png").similar(0.90))
click(Pattern("Toran.png".similar(0.90)) <-- closing bracket missing

Additional remark:
You use
andAndo = True
...
 andando = False
with capital letter and without.

Revision history for this message
Ricardo Luzini (rluzini) said :
#4

Thanks a lot for your support. I Noticed that every time I edited in Notepad++ and copied back to Siculi, a new different problem showed up.
I just rewrite everything inside Siculi and it is working now.
Again, thanks for @RaiMan and @Manfred support.