ImageSearch

Ask gaming related questions (AHK v1.1 and older)
fug5333
Posts: 32
Joined: 03 May 2016, 08:55

ImageSearch

13 Oct 2019, 13:19

Wondering if there is something obvious I'm doing wrong and maybe a tip to make this work.

This is a 2D side scrolling game and I'm trying search for a chest image as it goes by. They are on random stages. I'm trying to search an area and click the image. Should be easy..

Code: Select all

ImageSearch, FoundX, FoundY, 0, 300, 800, 500, chest.png
					
	If ErrorLevel = 1 	; If not Found	
               {
		sleep 10
		SoundBeep
		}				
	else 
		{
		If ErrorLevel = 0					
		Click, %FoundX%, %FoundY%  ; Click on it.						
		sleep, 1000
		}
Return
Bottom line, absolutely nothing happens. Hoping at least for the SoundBeep to go off.

Thanks!
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: ImageSearch

13 Oct 2019, 13:34

Perhaps ErrorLevel is 2:
https://www.autohotkey.com/docs/commands/ImageSearch.htm#Error_Handling wrote:ErrorLevel is set to 0 if the image was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).
Is the file path correct?
Add msgbox % errorlevel for testing after the Imagesearch line.
fug5333
Posts: 32
Joined: 03 May 2016, 08:55

Re: ImageSearch

13 Oct 2019, 15:02

I made the change to 'errorlevel 2' and I get a 'beep' now. I guess that's good? :) The msgbox shows a '2'. It looks like if the script found the image, it would click on it. So I assume the image is not to be found. 'errorlevel 2' sounds like a bad image.. Problem is, it's there! It's cropped in so it doesn't pull any colors from the background I pulled it from. It's a screenshot and unaltered, so should be right.

Here's the image I'm using: https://imgur.com/a/sGmNkPw

Thanks!
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: ImageSearch

13 Oct 2019, 15:25

Code: Select all

ImageSearch, FoundX, FoundY, 0, 300, 800, 500, C:\MyImages\Are\in\This\Folder\Path\chest.png
When the PATH is not specified the image needs to be in the same folder as the script.
fug5333
Posts: 32
Joined: 03 May 2016, 08:55

Re: ImageSearch

13 Oct 2019, 15:35

It is in the same folder. Made sure of that one! :)

It will click on them when the mouse is over the chest. It appears any time the script is run, the mouse clicks, but I need it to search!
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: ImageSearch

13 Oct 2019, 16:11

If it clicks when you mouse over the chest then the image is different when moused over vs not moused over.
Retake your image with the mouse not on the chest.
You may also need to add variation to the imagesearch.
fug5333
Posts: 32
Joined: 03 May 2016, 08:55

Re: ImageSearch

13 Oct 2019, 16:37

Mouse was not near it. I took another screenshot and cropped it tight to make sure.

I have confirmed that it clicks the mouse, but only where the cursor is and it does it every time the script is run.
fug5333
Posts: 32
Joined: 03 May 2016, 08:55

Re: ImageSearch

14 Oct 2019, 06:57

This is through Bluestacks. Is it blocking imagesearch? It doesn't seem to effect my other scripts.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: ImageSearch

14 Oct 2019, 10:35

If you are still getting ErrorLevel = 2 you need to fix that first.
Once that is fixed then make sure to set CoordMode appropriately.
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

Re: ImageSearch

15 Oct 2019, 04:34

1. you must verify if coordinate were "search" are relative screen desktop or bluestack window (read ImageSearch help)
2. set CoodMode to "screen" if bluestack are not active every time you use macro
3. "click" are also relative to active windows .. so ... change coordmode or put, into your macro, command to make bluestak "active" every time you start macro
4. use this (see help: *n (variation)): ImageSearch, FoundX, FoundY, 0, 0, 550, 360, *80 C:\Pics\test.bmp

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 70 guests