Image search looping.

Ask gaming related questions (AHK v1.1 and older)
Smajlinger
Posts: 11
Joined: 06 Nov 2016, 16:35

Image search looping.

20 Aug 2017, 09:17

Hello everyone!

I am semi expirienced with ahk. I have done some simple scripts but now I am heading some more complicated problem and i couldnt find a good solution.

I want to make a script wchich will be loooking for images in certain area and then move items to desire destination. Problem is with looping.

After first loop if script found image all seems to be fine, but in next loop script is start from all again and that's consume a lot of time and CPU.

Could you guys look at my code below and give me some tips how can I improve performance of my script?

Also is it possible to not see my moving cursor at screen during script is working?

Thank you guys in advance!

Code: Select all

insert::
SetBatchLines, -1

MouseGetPos, x1, y1
Loop 40

{
ImageSearch, pX, pY, 1570, 300, 1745, 815, *2, C:\Users\Sylwek\Desktop\loot_mary\item%a_index%.png
if ErrorLevel = 0
   {
	
       	SetDefaultMouseSpeed, 0
    	MouseClickDrag, Left, %pX%, %pY%, %InvX%, %Invy%
	sleep, 250
	
	
   }

}
MouseMove, %x1%, %y1%

return
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Image search looping.

22 Aug 2017, 19:49

Few things here.

SetBatchLines may be used before the hotkey (assuming this is you're entire script). Also consider that this is likely your main factor of CPU usage, and leaving it at default, or at least not -1, would lower the CPU usage.
There should be no comma between the options and file name (*2 and the path). I'm actually quite surprised that doesn't throw you an error or something.
SetDefaultMouseSpeed, same as SetBatchLines (only needs to be called once above the hotkey, assumption in place).
Smajlinger wrote:Also is it possible to not see my moving cursor at screen during script is working?
See ControlClick. Since it looks like this is for a game, that likely will not work, as most don't respect control-based input like that.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Cmecu and 91 guests