Call function

Asked by popstyle

Hello,
First his project is so great, thx to share it =)
I'm french and i don't speak very well english so i tried to explain my problem well.
I don't have any quality on java dev, and i like the "ludic" way of sikuli but i'm blocking...

I do this loop :
#Search function
while exists(X) == None:
   sleep(10)
   exists(X)

#Command function
if exists(X) and exists(Y):
  click(X)
  My problem is here... (when the command line is done i would like to redo the search loop... and i don't know how to do this, my bad =/

I need to recall the function but i don't know how to do.

Can you help and tell me how can i maybe optimise the code...

Thank you

pop

Question information

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

BTW Sikuli speaks Python, which is much easier to learn and handle than Java ;-)

This is the basic approach: (already looked at FAQ 1437 ?)

see comments below --X

while True: #--1

  #Search function
  while not exists(X, 0): #--2
    sleep(10)

  #Command function
  if exists(Y): #--3
    click(X)

print "Now we have left the While True: loop"

-- comments

--1 this will loop FOREVER, which is principally not good idea since you would have to interrupt Sikuli with the abort key combination

to test it, this would go:
for i in range(10): # would loop 10 times

exists(X, 0) does not wait 3 seconds, but comes back after first try. This easier to calculate the time.

normally you should have a conditional break somewhere in the loop, to end it (if condition: break)

--2 this will loop until X shows up. will loop FOREVER, if X does not show up
again you could use a counting loop:

for i in range(60): # this would loop about 70 seconds
  if exists(X, 0): break
  wait(10)

--3 exists(x) not needed - we know already it is there from the previous while loop

here is the question, what should happen if the click fires? It will instantly go back to #--1 as it would in the case either X or Y are not visible.

Can you help with this problem?

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

To post a message you must log in.