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

    Status: Open => Answered

RaiMan proposed the following answer:
--- some comments
while True:
    if not exists(adv, 0):
        break #leave the loop
    # now we check the top level actions
    if exists(adv, 0):
        click(adv)

does not really make sense: depending how the button appears and
vanishes when clicked this might either lead to excessive clicks or to a
loop lasting to long.

if you want to handle such a sequence at game start as mentioned above,
where you wait on something, then click it and then wait for the next
visual to appear, the easiest is this:

click(wait(first, 10))
click(wait(second, 10))
click(wait(third, 10))
....

the 10 is the max waiting time (if exceeded gives a FindFailed script abort) 
and should be set appropriate for the different steps.
In all cases: if the visual (first, second, third, ...) appears, it will be 
clicked immediately and the next wait() will start.

--- speed
as already mentioned in the prior comments: specifying a region smaller than 
the screen might reduce the search time dramatically (whole screen: 0,5 to 1 
sec, small regions: down to some milli sec)

--- regions
But this is not a must from the beginning, it is more an optimisation in the 
second step. Only in cases, where searching the whole screen might lead to 
false positives , using regions might help.
But usually having good shots (as little surrounding background as possible, 
concentrated on the key aspects) and  using Pattern().similar(0.9) should 
already do the job.

Using regions:
#SRB Arena
srbregion = Region(45,35,427,643)
level = "1385933213128.png"
go = "1385933505624.png"
while True:
    if not srbregion.exists(go,0):
        break #leave the loop
    if srbregion.exists(go,0):
        click(srbregion.getLastMatch())

--- handling alternatives
If your script comes to the point, that now this or that or that might happen, 
again there are many possibilities to handle.
the easiest (as already mentioned in comment above)

while true:
    if exists(go, 0):
        processGo()
    if exists(battle, 0):
        processBattle()
    if exists(items, 0):
        processItems()

generally: you should go back to the above comments and implement more things 
to make your script more structured.
The workflow you mentioned in comment #6 is not obvious, when going through 
your script.

-- 
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