Loop script won't work

Asked by Mike

Hi all,

I am trying to loop a script, here is my script. Please help me and tell me what i am doing wrong. Still Learning!!!

# --- this loops as long as img is visible
if exists(this image is for it to repeat loop), 0):
   click getLastMatch()
   if exists(this image is for it to brack loop and continue ):
      continue # skip the rest and start next turn
popup("Under ATTACK!")

But i get this error coming up:

[error] Stopped [error] An error occurs at line 61 [error] Error message: SyntaxError: ("mismatched input ',' expecting COLON", ('C:\\Users\\Mike\\AppData\\Local\\Temp\\sikuli-tmp7966962382069001658.py', 61, 30, 'if exists("1312842456395.png"), 0):\n'))

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:

This question was reopened

  • by Mike
Revision history for this message
Mike (mikewebbcp) said :
#1

This is how i wanted it too be:

IF image1 exists repeat from beginning of script, IF image2 exists break and continue to next turn.....

# --- this loops as long as img is visible: I think i got this wrong as what it to loop when it sees image1
if exists(image1 is for it to repeat loop), 0):
   click getLastMatch()
   if exists(image2 is for it to brack loop and continue ):
      continue # skip the rest and start next turn
popup("Under ATTACK!")

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

this is rather easy ("mismatched input ',' expecting COLON" means: did expect a : instead of a , ;-)

if exists(this image is for it to repeat loop, 0):

the 0 is a 2nd parameter for exists and has to be inside the brackets.

happy learning ;-)

Revision history for this message
Mike (mikewebbcp) said :
#3

OK thank you, that's done but now got error on click getLastMatch()

[error] Error message: SyntaxError: ("mismatched input 'getLastMatch' expecting NEWLINE", ('C:\\Users\\Mike\\AppData\\Local\\Temp\\sikuli-tmp1479893245292668079.py', 62, 9, ' click getLastMatch()\n'))

 click getLastMatch(whats meant to be here) is this the right one for it to start again at top of script, first image.....!!!

# --- this loops as long as img is visible
if exists(img1 , 0):
   click getLastMatch()
   if exists(img2 ,0):
      continue # skip the rest and start next turn
popup("Under ATTACK!")

Revision history for this message
Mike (mikewebbcp) said :
#4

Thanks RaiMan, that solved my question.

Revision history for this message
Mike (mikewebbcp) said :
#5

Thats was for first question lol!!!

Revision history for this message
Mike (mikewebbcp) said :
#6

RaiMan (raimund-hocke) solved my second question about getLastMatch()

It was meant to be like this

click(getLastMatch(img))

# --- this loops as long as img is visible
if exists(img1 , 0):
   click(getLastMatch(img))
   if exists(img2 ,0):
      continue # skip the rest and start next turn
popup("Under ATTACK!")

I got one last problem and my whole script should be complete, I hope!

Just before the loop i got, a wait(img) but when it comes to that it stops straight away. What i need is for it to wait for that img to appear, then continue..... Do i need to set a time like wait(700 img) as would rather not set a time and have it wait till the img appear.

Revision history for this message
Mike (mikewebbcp) said :
#7

Thanks RaiMan, that solved my question.

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

wait(img, time value_in_seconds)

If you are sure, that the image comes up in any case:

wait(img, FOREVER)

but if image never comes, you have to kill Sikuli ;-)