my script reacts too slow when detecting the image, how to improve it?

Asked by tony

I am making a script that make my character do the fishing automatically
fishButton = "fishingrod.png"
fishAppear = "exclamationMark.png"
getFish = Pattern("pullBackFishRod.png").targetOffset(2,0)
Settings.MoveMouseDelay = 0

# this three lines will click on the fishButton to drop the fish road to the sea
if exists(fishButton):
    for x in range(4):
        click (fishButton)

# after the fish rod drop to the sea, I wait for the fish to get hooked, when the fish get hooked, there will be an exclamation mark show up for about 1 second.
# so I wait for the fishAppear image to show up
wait(fishAppear, 2 * 60)
if exists(fishAppear):
    for y in range(4):
        click(getFish)

the problem now is: the getFish button only show up for like 1 second after the fish get hooked.
When the script detects fishAppear, then it take some time to click on the getFish button, which the getFish button already disappeared.

How can I make the script faster but so it can search the fishAppear image faster?
Thanks!

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
Manfred Hampl (m-hampl) said :
#1

see e.g. https://answers.launchpad.net/sikuli/+question/663281

make search region as small as possible around the place where you expect the image to appear.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

if nothing else is said, images are searched on the whole screen.
The search would be faster, if you restrict the region as much as possible to the area, where you expect the image to appear.

On large screens in most cases it is enough to restrict to the app window:
searchArea = App.focusedWindow()

now you might define additional search areas relative to the (x,y) of your primary area
see: https://sikulix-2014.readthedocs.io/en/latest/region.html#extend-regions-and-create-new-regions-based-on-existing-regions

I do not understand, why you click 4 times using the image:
if exists(fishButton):
    for x in range(4):
        click (fishButton)

my variant:
click(wait(fishButton))

or for more control:
if exists(fishButton):
    click() # clicks on the last match

now a region, where you expect things to happen:
reg = ... # somehow define it

if reg.exists(fishAppear, 2 * 60):
    reg.click(getFish) # see comment

comment: this should work, since if nothing else is said, the search repeats for 3 seconds.

Another aspect to look at: Settings.WaitScanRate
This 3 in the standard, meaning 3 searches per second max, which normally is sufficient.

In special cases, when you have small search areas, where a search might take only some 10 milli secs you might raise this value to a higher value (e.g. 10 means max 10 searches per second, which only makes sense, if searches ar faster then 100 milli secs).
Higher values don't do any harm, but only have an effect, if the search times fit.

Can you help with this problem?

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

To post a message you must log in.