Wait for Getpixel, act when changed

Ask gaming related questions (AHK v1.1 and older)
DaSilver
Posts: 3
Joined: 04 Mar 2020, 11:36

Wait for Getpixel, act when changed

04 Mar 2020, 11:43

Good day, everyone!
Been using a code suggested in another thread by Capn Odin and it worked fine. But now I'd like to add an additional function to it. Here's the original code:

Code: Select all

toggle := false

F6::SetTimer, CheckColour, % (toggle := !toggle) ? "250" : "Off" ; Evaluats the label CheckColour every 0.25 sec or turns it off depending on "toggle"

CheckColour:
	PixelGetColor, Res, 712, 1017, RGB ; 1050,907Gets the colour at the coordinates (100, 100) in the active window
	if(Res = 0x46D507){ ; checks the found colour
		SetTimer, clk, 50, On
	} else { ; 
		SetTimer, clk, Off
	}
	ToolTip, % Res, 100, 0 ; Displays the found colour in the upper left corner of the active window
Return

clk:
{
	sleep 500
	Send, i
	sleep, 500
	Click, left, 458, 400
	sleep, 500
	Click, left, 458, 550   ; 550-500
	Sleep, 5000
}
return
Numpad9::exitapp
What I want it to do is to wait until color 0x46D507 pops up, then wait for it to change (not equal to 0x46D507) and only then execute "clk:". After clk executed wait for color 0x46D507 again. Repeat. Any ideas? Thank you in advance
DaSilver
Posts: 3
Joined: 04 Mar 2020, 11:36

Re: Wait for Getpixel, act when changed

05 Mar 2020, 04:37

I tried adding like this:

Code: Select all

toggle := false

F6::SetTimer, CheckColour, % (toggle := !toggle) ? "250" : "Off" ; Evaluats the label CheckColour every 0.25 sec or turns it off depending on "toggle"

CheckColour:
	Pixelsearch, Res, 1060, 930, RGB ; 1050,907Gets the colour at the coordinates (100, 100) in the active window
	if(Res = 0xEDB50F){      ; checks if the found colour is completely RED
		SetTimer, clk1, on
	} else { ; checks if the found colour is WHITE
		SetTimer, clk1, off
	}
	ToolTip, % Res, 100, 0 ; Displays the found colour in the upper left corner of the active window
Return

clk1:
{
	if(Res = 0xEDB50F) {
		SetTimer, clk2, off
		} else {
		SetTimer, clk2, on
		}
}
Return

clk2:
{
	sleep 500
	Send, i
	sleep, 500
	Click, left, 458, 400
	sleep, 500
	Click, left, 458, 550   ; 550-500
	Sleep, 5000
}
return
Numpad9::exitapp
But I get an error "Parameters 3 though 7 must not be a blank"
DaSilver
Posts: 3
Joined: 04 Mar 2020, 11:36

Re: Wait for Getpixel, act when changed

05 Mar 2020, 09:36

So I've solved the error. Turns out I'm dumb for not noticing that after I experimented a bit with it I forgot to change "PixelSearch" back to "PixelGetColor". The Script now works, but in a strange way. On initial launch it worked just as intended, but after some time it just stopped repeating.
Is there a way to "wait for next step" thing?

Code: Select all

toggle := false

F6::SetTimer, CheckColour, % (toggle := !toggle) ? "250" : "Off" ; Evaluats the label CheckColour every 0.25 sec or turns it off depending on "toggle"

CheckColour:
	PixelGetColor, Res, 1060, 930, RGB ; 1050,907Gets the colour at the coordinates (100, 100) in the active window
	if(Res = 0xEDB50F){      ; checks if the found colour is completely RED
		SetTimer, clk1, on
	} else { ; checks if the found colour is WHITE
		SetTimer, clk1, off
	}
	ToolTip, % Res, 100, 0 ; Displays the found colour in the upper left corner of the active window
Return

clk1:
{
	PixelGetColor, Res, 1060, 930, RGB
	if(Res = 0xEDB50F) {
		SetTimer, clk2, off
		} else {
		sleep 500
	Send, i
	sleep, 500
	Click, left, 458, 400
	sleep, 500
	Click, left, 458, 550   ; 550-500
	Sleep, 5000
		}
}
Return

clk2:
{
	sleep 500
	Send, i
	sleep, 500
	Click, left, 458, 400
	sleep, 500
	Click, left, 458, 550   ; 550-500
	Sleep, 5000
}
return
Numpad9::exitapp
and to end the step clk2 or to run it only once?

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 34 guests