leaving a loop at some condition

Asked by felipe cavalcante

hi, am beginner, and I'm having difficulty in this, after entering "while wewait" I can not go back to "while true". really want to make an infinite sequence continues with this script. I think in "if not (md1 and md2)": I can put it back to a command "while true" or the first line.
is that all right? help me please

while True:
wait(img, forever)
click (img,5)
wewait=5
while wewait>1:
md1=exists(md1)
md2=exists(md2)
if md1 or md2:
wait(1)
wewait-=1
if not (md1 and md2):
???????????????????
if md1:
click(img)
click(img)
click(img)
if md2:
click(img)
click(img)
click(img)
click(img)

Question information

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

Sikuli talks Python language, so the script must follow the syntax needed for Sikuli scripts.

One major point is indentation to identify blocks of code after while/for/if/else/def/... that belong together (see faq 1800)

while True:
    wait(img, forever)
    click (getLastMatch())
    wewait=5
    while wewait>1:
        md1=exists(md1)
        md2=exists(md2)
        if md1 or md2:
            wait(1)
            wewait-=1
        if not (md1 and md2):
            break # leaves inner loop (-> Label1)
        if md1:
            click(img)
            click(img)
            click(img)
        if md2:
            click(img)
            click(img)
            click(img)
            click(img)
        # end of inner loop, goback to
        # while wewait > 1
    #Label1: here we are after inner loop ends
    # go back to while True

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

BTW: since I do not know the logical workflow behind your script, this might not be what you intend, but it shows the principles.

--- getLastMatch()
it just recalls the last match, so you do not need to repeat the same find operation (1 second saved ;)

Revision history for this message
felipe cavalcante (felipel-2-0) said :
#3

thanks