Will ImageSearch slow down your game/computer if used in a loop?

Ask gaming related questions (AHK v1.1 and older)
Jono91
Posts: 18
Joined: 09 Oct 2020, 13:04
Contact:

Will ImageSearch slow down your game/computer if used in a loop?

Post by Jono91 » 14 May 2021, 10:43

I have this script set up to constantly spawn an enemy, click the attack button, click a couple times to go back into the overworld, wait a little bit, and then start again:

Code: Select all

Loop
{
ToolTip , "Sending Numpad"
Send, {Numpad5}
ToolTip , "Sent Numpad"
Sleep, 2500
Click, 876 800
ToolTip , "Sending Click1"
Sleep 8000
ToolTip , "Sending Click2"
Sleep 1000
ToolTip , "Sending Click3"
Click, 994 536
Sleep 2500
}
I'm a little rusty with my AHK programming so the formatting is a little shit and I'm not sure I got the syntax completely right (the tooltips were for initial debugging), it works though. I'm just wondering if instead of heavily relying on "sleep", I can set multiple images to different Boolean variables and put them in a big while loop, so instead of sleeping for eight seconds, it keeps a look out for the EXP screen, and then waits until it sees my player in the overworld, etc. I'm just not sure how AHK looks for the images if in a loop.

I guess I need a little help in getting the logic right here, and whether this is a relatively safe thing to set up in terms of not slowing down my PC.
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Will ImageSearch slow down your game/computer if used in a loop?

Post by mikeyww » 14 May 2021, 12:01

The answer is... try it! You can have a looped search if you like. For search itself, see example. ErrorLevel tells you whether the image was found.
Jono91
Posts: 18
Joined: 09 Oct 2020, 13:04
Contact:

Re: Will ImageSearch slow down your game/computer if used in a loop?

Post by Jono91 » 17 May 2021, 13:47

My code works but it acts funny. After it finds the image it doesn't click the picture like it's supposed to, it just swings off to the left of the monitor for some reason.

Edit: Fixed by deleting CoordsMode, I thought you had to do that to calibrate the screen.

Code: Select all

CoordMode, Mouse, Screen

foundImage = 0

while (foundImage == 0) {	
	ImageSearch, X, Y, 0, 0, 1920, 1080, 2021-05-17 19_12_55-Nox.png

	if (ErrorLevel == 0) {
		foundImage = 1

		MouseClick, left, X, Y
	}

}
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Will ImageSearch slow down your game/computer if used in a loop?

Post by mikeyww » 17 May 2021, 13:54

CoordMode changes the point of reference. If you change it for the click but not the search, unexpected results would often occur. In many cases, using the default of the active window works. Otherwise, for a routine that uses both search & click, you'd likely want to change it for both.
Post Reply

Return to “Gaming Help (v1)”