beginner how can i say sikuli to go back to lne 1 ?

Asked by elias maure

  #
    hanf = exists(...)

    while hanf:
        click(...)
        hanf = exists(...)
        type(Key.ENTER)
        los = exists(...)
        if los :

            click(Pattern(...)
            boden = exists(....)
            if boden :
                click( ....)

            wait(...)
            ((text))
            click("KRDTHLETT-1.png" )

  when sikuli are here that he go to line 1

Question information

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

You either rap the whole stuff into another loop

while True: #endless
    hanf = exists(...)
    while hanf:

or you redesign your existing loop:

hanf = exists(...)
while hanf:
    click(...)
    hanf = exists(...)
    # many other statements
    hanf = exists(...) # as last statement in the loop

More ideas on looping: faq 1437

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

You either rap the whole stuff into another loop

while True: #endless
    hanf = exists(...)
    while hanf:

or you redesign your existing loop:

hanf = exists(...)
while hanf:
    click(...)
    hanf = exists(...)
    # many other statements
    hanf = exists(...) # as last statement in the loop

More ideas on looping: faq 1437

Revision history for this message
elias maure (eliasmaure) said :
#3

Oh thanks a lot man :D

Revision history for this message
Deses (deses12) said :
#4

Make a function and make it call itself recursively?

Just make sure to add a flag to exit the loop when you are done, or that "hanf" will eventually not exist.

def hanf():
    hanf = exists(...)

    while hanf:
        click(...)
        hanf = exists(...)
        type(Key.ENTER)
        los = exists(...)
        if los :
            click(Pattern(...)
            boden = exists(....)
            if boden :
                click( ....)
            wait(...)
            ((text))
            click("KRDTHLETT-1.png")
 hanf()

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

@Deses
this does not do the requested job and is not a recursion.
On top, you have a name overlay with hand.

A recursive version would be:

def fHanf():
    hanf = exists(...)
    while hanf:
        click(...)
        hanf = exists(...)
        type(Key.ENTER)
        los = exists(...)
        if los :
            click(Pattern(...)
            boden = exists(....)
            if boden :
                click( ....)
            wait(...)
            ((text))
            click("KRDTHLETT-1.png")
        fHanf() # here the recursion happens
    # hanf() will exit, when hand does not exist any longer

 fHanf()

But I do not recommend to use recursion for these cases (risk of stack memory overflow).
I simple correctly setup while loop does the job very well.

Revision history for this message
Deses (deses12) said :
#6

Damn, the indentation got wrong there. But otherwise you are right, it's tricky to do if you don't are sure of what you are doing.