Question #171331 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/171331

    Status: Open => Answered

RaiMan proposed the following answer:
The idea with the def(s) is not so bad: this makes the main workflow
more readable.

But the principal structure for these situations is:

while True: # see comment below

    while not exists(manster): 
        if exists(hemp): click(hemp)
        if exists(gather): click(gather)
        if exists(lvlup): click(lvlup)

    while exists(manster): 
        if exists(ready): click(ready)
        if not exists(gobs): click(iop)
        if exists(lock): click(lock)
        if exists(gobs): click(turn)
        if exists(fish): click(fish)

--- comment on exists()
Your construct constantly looks for some images. Each exists takes 3 seconds 
(standard waiting time), if the image is not found. This makes the loop very 
slow.
You might use exists(img, 0), which comes back in any case after the first 
search trial (max 0.5 seconds for the whole screen)
This is even worth with "not exists()": you want to do something if an image is 
not there, but it only happens after the 3 seconds, which is really not 
necessary in this case.

--- comment on if exists(fish): click(fish)
You are looking for something and want to click it, if it is there. Your 
solution makes another search for the same image in the click() - not efficient.
 if exists(fish): click(getLastMatch())
just clicks what was already found by the exists() --- much faster

--- comment on while True:
If you want to repeat something, you have to pack it into a loop. While True 
will repeat the loop body for ever - so you have to use the 
GlobalIntterruptKey, if you want to stop it.

If you want the loop to stop on some condition, either use
while condition: # instead of while True

or somewhere inside the loop:
if not condition: break

In both cases, the loop will end, if condition evaluates to False.

or:
while not condition:
or:
if condition: break

will end the loop if condition evaluates to True

There is a faq on loops: faq 1437

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp

Reply via email to