Image identification loop

Get help with using AutoHotkey and its commands and hotkeys
Bergsta
Posts: 3
Joined: 27 Aug 2018, 05:54

Image identification loop

08 Aug 2020, 02:59

I'm trying to find an image on my screen and if it finds the target image stop looking but if it does not find it keep looking as the screen will be changing.
The Image finding is not working
The loop will not stop after 5 tries

Code: Select all

F4::
a = 0
MyLabel:
		if (a = 5) 
		goto MyLabel2
Sleep, 1000
ImageSearch, FoundX, FoundY, 59, 140, 309, 334, C:\Users\lochi\Desktop\Scripting\Capture.png
	if (ErrorLevel = 2){
		MsgBox Could not conduct search
		}
	else if (ErrorLevel = 1){
		Sleep, 1000
		MsgBox, , COC, No Base Found, 0.5
		a = a + 1
		Goto, MyLabel
		}

	else if (ErrorLevel = 0)
		MouseClick, left, 177, 765
	MyLabel2:
return
Last edited by gregster on 08 Aug 2020, 04:50, edited 1 time in total.
Reason: Moved to 'Ask For Help'.
User avatar
boiler
Posts: 5909
Joined: 21 Dec 2014, 02:44

Re: Image identification loop

08 Aug 2020, 05:28

Use the expression assignment operator := when assigning a := a + 1. However, that’s a convoluted way to implement a simple loop.

Code: Select all

F4::
	loop, 5 {
		Sleep, 1000
		ImageSearch, FoundX, FoundY, 59, 140, 309, 334, C:\Users\lochi\Desktop\Scripting\Capture.png
		if (ErrorLevel = 2)
			MsgBox Could not conduct search
		else if (ErrorLevel = 1) {
			Sleep, 1000
			MsgBox, , COC, No Base Found, 0.5
		}

		else if (ErrorLevel = 0) {
			MouseClick, left, 177, 765
			return
		}
	}
return
As for why it’s not finding the image, make sure the CoordMode is set appropriately. You might try some allowable variation in the ImageSearch.
User avatar
Chunjee
Posts: 666
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: Image identification loop

08 Aug 2020, 13:46

Capture.png gives me the impression that the ImageSearch needle is too large. But I have no way of knowing because it isn't attached
Bergsta
Posts: 3
Joined: 27 Aug 2018, 05:54

Re: Image identification loop

08 Aug 2020, 23:08

boiler wrote:
08 Aug 2020, 05:28
Use the expression assignment operator := when assigning a := a + 1. However, that’s a convoluted way to implement a simple loop.

Code: Select all

F4::
	loop, 5 {
		Sleep, 1000
		ImageSearch, FoundX, FoundY, 59, 140, 309, 334, C:\Users\lochi\Desktop\Scripting\Capture.png
		if (ErrorLevel = 2)
			MsgBox Could not conduct search
		else if (ErrorLevel = 1) {
			Sleep, 1000
			MsgBox, , COC, No Base Found, 0.5
		}

		else if (ErrorLevel = 0) {
			MouseClick, left, 177, 765
			return
		}
	}
return
As for why it’s not finding the image, make sure the CoordMode is set appropriately. You might try some allowable variation in the ImageSearch.
This has fixed my loop thank you
Chunjee wrote:
08 Aug 2020, 13:46
Capture.png gives me the impression that the ImageSearch needle is too large. But I have no way of knowing because it isn't attached
I used the snipping tool to capture a small image(26px*26px)
Capture.PNG
Capture.PNG (1.35 KiB) Viewed 230 times

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], mikeyww, PlumpSamurai and 67 guests