How to shorten time with tons of exists() if-statments

Asked by o wea on 2017-11-28

Hi, i am playing a game and unlocking toons from time to time, when i had 10 before, my code was working fine. but now i have 30+ toons, some of them take almost 5-10 mins to start choosing their task. my code is as follows:

        if tasktitle.exists(Icon1):
            # 6 mins task
            CharacterIndex = Toon1 # Toon1 = 1
        elif tasktitle.exists(Icon2):
            # 6 mins task
            CharacterIndex = Toon2 # Toon2 = 2, etc...
        elif tasktitle.exists(Icon3):
            # 8 min task
            CharacterIndex = Toon3
        elif tasktitle.exists(Icon99):
            # 8 min task
            CharacterIndex = Toon99

i read the manual and i tried Settings.ObserveScanRate can be changed but not quite helpful
For example,
        Settings.ObserveScanRate = 0.01

        if tasktitle.exists(Icon1):
            # 6 mins task
            CharacterIndex = Toon1
        elif tasktitle.exists(Icon2):

        Settings.ObserveScanRate = 1

Some toons still take age to start choosing their task.
Any idea how i can improve my situation?
Maybe you can advise some scenario to achieve my goal since i am not expert in programming.

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

exists(img, 0)

which only searches once and then comes back, which only takes about some 10 milliseconds.

ObserveScanRate/WaitScanrate are only the presets, to decide how often per second SikuliX searches for the image while waiting for it to come up.

- use latest SikuliX (>= 1.1.1)
- know the docs:

o wea (omegawea) said : #2

wow, such a quick response!!! thanks!
your magic improved the loop time from 162s to 11s.

i think i will apply this to all my exists() check.
do u think there is any issue with it?

Best RaiMan (raimund-hocke) said : #3

using exists(img, 0) makes sense in situations like you have (a series of checks for alternatives) and if you do not use the implicit wait (standard 3 seconds), but loop around one or more exists(img, 0) making your own "wait" logic.

Since GUI's usually have their reaction times of up to 500 milliseconds (not visible for humans), you must be careful with exists(img, 0) in situations, where you check after an action like click, that is interpreted by the GUI.

This is the reason behind the standard wait time, which normally is the best choice for sequential workflows.

RaiMan (raimund-hocke) said : #4

... so the answer is:
do not generally use exists(img, 0), but only in situations where it really makes sense.

o wea (omegawea) said : #5

Thanks RaiMan, that solved my question.