PixelSearch saying it found the right color even though it's not there

Get help with using AutoHotkey and its commands and hotkeys
Nzthxn
Posts: 8
Joined: 07 Feb 2018, 11:23

PixelSearch saying it found the right color even though it's not there

07 Feb 2018, 14:43

Code: Select all

LAlt::
SetMouseDelay,-1
CoordMode, Pixel, Relative
CoordMode, Mouse, Relative

Loop
{
	Sleep 1000
	PixelSearch, Px, Py, 430, 60, 1210, 850, 0x130000, 5, Fast RGB
	if ErrorLevel,
		Return
	else
		Click, %Px%, %Py%
	Loop
	{
		;This is where it keeps messing up, it keeps flashing that the color is currently found even though it's not there
		Sleep 250
		PixelSearch, Px, Py, 1000, 50, 1140, 70, 0x1A561D, 5, Fast RGB
		if !ErrorLevel,
			MsgBox, Color not found!
			break
		else
			tooltip, color currently found
			Sleep 500
			tooltip
		
	}
	Sleep 1000
}

MsgBox, Script Ended.

Esc::ExitApp
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: PixelSearch saying it found the right color even though it's not there

07 Feb 2018, 15:18

Not sure what part you're having problems with, but you're lacking brackets around

Code: Select all

		if !ErrorLevel,
			MsgBox, Color not found!
			break
		else
			tooltip, color currently found
			Sleep 500
			tooltip
Brackets should group your MsgBox/break and the tooltip/sleep/tooltip. Otherwise, it always breaks. But also, you're saying the color was not found, despite using the If !ErrorLevel -- 0x1A561D, if found, would make ErrorLevel 0, and !0 is considered true, which means the MsgBox does not correlate with the color being found.

Try putting your brackets in and double checking that your If !ErrorLevel logic is correct. (Also, I do not know if the commas at the end are having any affect. It may be good to drop them.)
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: PixelSearch saying it found the right color even though it's not there

08 Feb 2018, 15:27

As Exaskryz suggested might be the case, your Errorlevel logic is backwards. PixelSearch returns 0 if the color is found and 1 if it was not found, so you need to do:

Code: Select all

		if ErrorLevel
        {
			MsgBox, Color not found!
			break
        }
		else
        {
			tooltip, color currently found
			Sleep 500
			tooltip
        }
Note the removed exclamation mark and the added braces, as Exaskryz mentioned.

Return to “Ask For Help”

Who is online

Users browsing this forum: flyingDman, Getfree, Google [Bot], ineuw, kczx3, shipaddicted, thebib622 and 145 guests