Page 1 of 1

ImageSearch

Posted: 13 Oct 2019, 13:19
by fug5333
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!

Re: ImageSearch

Posted: 13 Oct 2019, 13:34
by gregster
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.

Re: ImageSearch

Posted: 13 Oct 2019, 15:02
by fug5333
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!

Re: ImageSearch

Posted: 13 Oct 2019, 15:25
by Xtra

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.

Re: ImageSearch

Posted: 13 Oct 2019, 15:35
by fug5333
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!

Re: ImageSearch

Posted: 13 Oct 2019, 16:11
by Xtra
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.

Re: ImageSearch

Posted: 13 Oct 2019, 16:37
by fug5333
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.

Re: ImageSearch

Posted: 14 Oct 2019, 06:57
by fug5333
This is through Bluestacks. Is it blocking imagesearch? It doesn't seem to effect my other scripts.

Re: ImageSearch

Posted: 14 Oct 2019, 10:35
by Xtra
If you are still getting ErrorLevel = 2 you need to fix that first.
Once that is fixed then make sure to set CoordMode appropriately.

Re: ImageSearch

Posted: 15 Oct 2019, 04:34
by scriptors
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