if error or cant finde image run last instruction

Asked by yazid amine on 2018-12-17

please can some one tel me haw to do

  def run last instruction()
          run ligne6 # 'click (6.png)' the last instruction after 'click (7.png)' in this example
          goto: 1 or execute line after ligne6 in this case ligne7 click (7.png) in this example

while exists (1.png):

          ligne1 click (1.png)
          ligne2 click (2.png)
          ligne3 click (3.png)
          ligne4 click (4.png)
          ligne5 click (5.png)
          ligne6 click (6.png)
      1: ligne7 click (7.png) (error can't find 7.png "for example") hi should run function 'run last instruction()'
          ligne8 click (8.png)
          ligne9 click (9.png)
          ligne10 click (10.png)
          ligne11 click (11.png)

ty for all im wating for solution

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-12-18
Last reply:
2018-12-18

This question was reopened

Jitendra patel (jpatel1011) said : #1

I think this is what you want if i understand correctly

this will click 6.png once if 7.png doesnt exsits it will click 6.png again and if 7.png still doesnt exists then it will start over at 1.png but if 7.png exists then it continues to 7 8 9..

def check7():
    if exists(6.png):
        click(getLastMatch())
    if exists(7.png):
        click(getLastMatch())
    else:
        return True
    return False

while True: #exists(1.png):
    click(1.png)
    click(2.png)
    click(3.png)
    click(4.png)
    click(5.png)
    click(6.png)
    reset = check7()
    if reset:
        continue
    click(8.png)
    click(9.png)
    click(10.png)
    click(11.png)

yazid amine (yamine19833) said : #2

Ty sir bat this solution is only for 7.png and 6.png I want solution for all the scripts (2000 lines) if didn't find any pic (on any line of the script) should run the last instruction and retail to click the pic you understand me now?

RaiMan (raimund-hocke) said : #3

see the docs for solutions with FindFailed.

RaiMan (raimund-hocke) said : #4

... generally there is no feature in SikuliX, that allows, to repeat a script from a specific line or repeat some lines before going on.

yazid amine (yamine19833) said : #5

please can you give me a solution with FindFailed :)

RaiMan (raimund-hocke) said : #6

Sorry, no time for that.

Be aware: what you want to do is more than complex.

A serious of (dumb) clicks without any intervening checks, does only make sense, if the series always works.

This apparently is not the case in your situation, hence you have to implement more logic, to assure the workflow.

yazid amine (yamine19833) said : #7

ty

Manfred Hampl (m-hampl) said : #8

What you want to achieve might be possible with an array of images and a loop.

Something like

img_list = ['1.png', '2.png', ...]
i = 0
while i < len(img_list):
    if exists(img_list[i]):
        click(getLastMatch())
        i += 1
    else:
        i -=1
    if i < 0:
        quit()

yazid amine (yamine19833) said : #9

ty

def handler(event):

        run (ligne7 -1) or a =get ligne() ; b = a-1 ; run b

       run ( ligne7) or run a

       go to ( ligne7+1) or c= a+1 ; go to c

    event.setResponse(RETRY)

setFindFailedHandler(handler)

while exists (1.png):

          ligne1 click (1.png)
          ligne2 click (2.png)
          ligne3 click (3.png)
          ligne4 click (4.png)
          ligne5 click (5.png)
          ligne6 click (6.png)
      1: ligne7 click (7.png) (error can't find 7.png "for example") hi should run function 'run last instruction()'
          ligne8 click (8.png)
          ligne9 click (9.png)
          ligne10 click (10.png)
          ligne11 click (11.png)

i cant interparte

        run (ligne7 -1) or a =get ligne() ; b = a-1 ; run b

       run ( ligne7) or run a

       go to ( ligne7+1) or c= a+1 ; go to c

ty for all

RaiMan (raimund-hocke) said : #10

        run (ligne7 -1) or a =get ligne() ; b = a-1 ; run b
       run ( ligne7) or run a
       go to ( ligne7+1) or c= a+1 ; go to c

nice try ;-) but this is not Python script language and what you ever do in this direction will not work,

as mentioned:
... generally there is no feature in SikuliX, that allows programmatically, to repeat a script from a specific line or repeat some lines before going on.

Using the FindFailed handler is basically a good idea, but now you have to make your click sequence aware of it.

something like that (no guarantee ;-)

def handler(event):
    global line, lines
    global shouldRepeat
    lines = range(line - 1, 2000)
    shouldRepeat = True

lines = range(1, 2000)
while True:
    shouldRepeat = false
    for line in lines:
        click(str(line)) # will get 1.png, 2.png, ...
        if shouldRepeat:
            break
    if not shouldRepeat:
        break

... click(1.png) should not fail !

RaiMan (raimund-hocke) said : #11

or with an image list (like Manfred Hampel suggested):

img_list = ['1.png', '2.png', ...]

...

        click(img_list[line])

allows to name the images as you like.

Can you help with this problem?

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

To post a message you must log in.