Issues with pixel comparing Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Valhalla188
Posts: 4
Joined: 15 Apr 2019, 19:56

Issues with pixel comparing

15 Apr 2019, 20:12

So I have a GUI which will prompt for Item location 1 and item location 2 (3 to come once i get it working). I am not sure if I am using the wrong code to compare the colors... but it will only click X1,Y1 and then it will not continue regardless of whatever color pixel is present. The radius click works great, and so does the random timer, but I cannot get the color comparison loops to work.

This is my first attempt at writing my own script... thanks for the help.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force	

;GUI Layout
;-----------------------------------------------------------
Gui,show, w400 h325, Valhalla's clicker	

Gui, font, cwhite
Gui, Color, Black
Gui, add, button, x65 y25 w100 h50 gcheck, 2 items
Gui, add, button, x235 y25 w100 h50, 3 items
Gui, add, button, x150 y100 w100 h35 grl1, First
Gui, add, button, x150 y145 w100 h35 grl2, Second
Gui, add, button, x150 y190 w100 h35 grl3, Third(opt)
Gui, add, button, x150 y235 w100 h35 gdrop, Last(opt)

return

;Labels
;-----------------------------------------------------------
rl1:
	ToolTip, click first
	KeyWait, LButton, D
	MouseGetPos, X1, Y1
	PixelGetColor R1, %MouseX1%, %MouseY1%
	KeyWait, LButton, U
	ToolTip
	return
rl2:
	ToolTip,  click second
	KeyWait, LButton, D
	MouseGetPos, X2, Y2
	PixelGetColor R2, %MouseX2%, %MouseY2%
	KeyWait, LButton, U
	ToolTip
	return	
rl3:
	ToolTip,  click third
	KeyWait, LButton, D
	MouseGetPos, X3, Y3
	PixelGetColor R3, %MouseX3%, %MouseY3%
	KeyWait, LButton, U
	ToolTip
	return
Check:
	MsgBox, X1: %X1% Y1: %Y1% X2: %X2% Y2: %Y2% X3: %X3% Y3: %Y3%
	return
Drop:
	ToolTip,  Click Last
	KeyWait, LButton, D
	MouseGetPos, X4, Y4
	PixelGetColor DropColor, %MouseX4%, %MouseY4%
	KeyWait, LButton, U
	ToolTip
	return

;Functions
;------------------------------------------------------------
click_InsideCircle(x,y,r) {
	Random, radius, 0, r
	Random, angle, 0, 6.283185307179586476925286766559		; 2*Pi = 360°
	x += Cos(angle)*radius
	y += Sin(angle)*radius
	Click %x%, %y%
}


;Hotkeys
;------------------------------------------------------------
^x::ExitApp

t:: 
MsgBox, RUNNING!
loop { ;MASTER LOOP
	
	loop{ ;CHECK1
		PixelGetColor, R1C, %MouseX1%, %MouseY1%
		Sleep, 50
		}until, %R1%=%R1C%
	
	Random, rand, 200, 1200
	Sleep, %rand%
	click_insidecircle(x1,y1,10)

	Loop{ ; CHECK2
		PixelGetColor, R1C, %MouseX1%, %MouseY1%
		Sleep, 50
		}until %R1%!=%R1C%
	
	loop{ ;CHECK3
		PixelGetColor, R2C, %MouseX2%, %MouseY2%
		Sleep, 50
		}until, %R2%=%R2C%
	
	Random, rand, 200, 1200
	sleep %rand%
	click_insidecircle(x2,y2,10)

	Loop{ ; CHECK4
		PixelGetColor, R2C, %MouseX2%, %MouseY2%
		Sleep, 50
		}until %R2%!=%R2C%
	
	PixelGetColor, DropColor2, %MouseX4%, %MouseY4%
} until DropColor != DropColor2
Valhalla188
Posts: 4
Joined: 15 Apr 2019, 19:56

Re: Issues with pixel comparing

16 Apr 2019, 08:49

I did that, and it still doesn't work. I've been using paint to try and simulate a couple boxes that change colors, but still cannot make it continue past CHECK2. Also added a way to check the color outputs and they never update after the loop is initiated the first time.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force	

;GUI Layout
;-----------------------------------------------------------
Gui,show, w400 h325, Valhalla's Clicker

Gui, font, cwhite
Gui, Color, Black
Gui, add, button, x65 y25 w100 h50 gcheck, 2 Items!
Gui, add, button, x235 y25 w100 h50, 3 Items!
Gui, add, button, x150 y100 w100 h35 grl1, First Loc
Gui, add, button, x150 y145 w100 h35 grl2, Second Loc
Gui, add, button, x150 y190 w100 h35 grl3, Third Loc (opt)
Gui, add, button, x150 y235 w100 h35 gdrop, Last Slot (opt)

return

;Labels
;-----------------------------------------------------------
rl1:
	ToolTip, click first location
	KeyWait, LButton, D
	MouseGetPos, X1, Y1
	PixelGetColor, R1, %MouseX1%, %MouseY1%, RGB
	KeyWait, LButton, U
	ToolTip
	return
rl2:
	ToolTip,  click second location
	KeyWait, LButton, D
	MouseGetPos, X2, Y2
	PixelGetColor, R2, %MouseX2%, %MouseY2%, RGB
	KeyWait, LButton, U
	ToolTip
	return	
rl3:
	ToolTip,  click third location
	KeyWait, LButton, D
	MouseGetPos, X3, Y3
	PixelGetColor, R3, %MouseX3%, %MouseY3%, RGB
	KeyWait, LButton, U
	ToolTip
	return
Check:
	MsgBox, R1: %R1% R1Check: %R1Check% R1Check2: %R1Check2%
	return
Drop:
	ToolTip,  Click Last Inventory Slot
	KeyWait, LButton, D
	MouseGetPos, X4, Y4
	PixelGetColor, DropColor, %MouseX4%, %MouseY4%, RGB
	KeyWait, LButton, U
	ToolTip
	return

;Functions
;------------------------------------------------------------
click_InsideCircle(x,y,r) {
	Random, radius, 0, r
	Random, angle, 0, 6.283185307179586476925286766559		; 2*Pi = 360°
	x += Cos(angle)*radius
	y += Sin(angle)*radius
	Click %x%, %y%
}


;Hotkeys
;------------------------------------------------------------
^x::ExitApp

t:: 
MsgBox, RUNNING!
loop { ;MASTER LOOP
	
	loop{ ;CHECK1
		PixelGetColor, R1Check, %MouseX1%, %MouseY1%, RGB
		Sleep, 50
		}until, %R1%=%R1Check%
	
	Random, rand, 200, 1200
	Sleep, %rand%
	click_insidecircle(x1,y1,10)
	Sleep, 50	

	Loop{ ; CHECK2
		PixelGetColor, R1Check2, %MouseX1%, %MouseY1%, RGB
		Sleep, 50
		}until %R1%!=%R1Check2%
	
	loop{ ;CHECK3
		PixelGetColor, R2C, %MouseX2%, %MouseY2% [,RGB]
		Sleep, 50
		}until, %R2%=%R2C%
	
	Random, rand, 200, 1200
	sleep %rand%
	click_insidecircle(x2,y2,10)

;	Loop{ ; CHECK4	
;		PixelGetColor, R2C, %MouseX2%, %MouseY2%, RGB
;		Sleep, 50
;		}until %R2%!=%R2C%
	
	PixelGetColor, DropColor2, %MouseX4%, %MouseY4%, RGB
} ;until %DropColor%!=%DropColor2%
Valhalla188
Posts: 4
Joined: 15 Apr 2019, 19:56

Re: Issues with pixel comparing

16 Apr 2019, 13:35

evilC wrote:
16 Apr 2019, 11:55
until %R1%!=%R1Check2% should be until R1 != R1Check2
Still not getting passed the 2nd Check. Thanks for taking a look at it though.

Code: Select all

loop { ;MASTER LOOP
	
	loop{ ;CHECK1 TEST IF COLOR MATCHES INITIAL INPUT
		PixelGetColor, R1Check, %MouseX1%, %MouseY1%, RGB
		Sleep, 50
		}until, R1 = R1Check
	
	Random, rand, 200, 1200
	Sleep, %rand%
	click_insidecircle(x1,y1,10)
	Sleep, 50	

	Loop{ ; CHECK2 WAIT UNTIL INITIAL COLOR CHANGES
		PixelGetColor, R1Check2, %MouseX1%, %MouseY1%, RGB
		Sleep, 50
		}until R1 != R1Check2
	
	loop{ ;CHECK3
		PixelGetColor, R2Check, %MouseX2%, %MouseY2%, RGB
		Sleep, 50
		}until,  R2 = R2Check
	
	Random, rand, 200, 1200
	sleep %rand%
	click_insidecircle(x2,y2,10)

	Loop{ ; CHECK4	
		PixelGetColor, R2Check2, %MouseX2%, %MouseY2%, RGB
		Sleep, 50
		}until R2 != R2Check2
	
	;PixelGetColor, DropColor2, %MouseX4%, %MouseY4%, RGB
} ;until %DropColor%!=%DropColor2%
I checked values of R1Check and R1Check2 and they are... 0xEDEDED and 0xFFFFFF
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Issues with pixel comparing  Topic is solved

18 Apr 2019, 04:45

MouseX1 is never set. It looks like you intend to do a MouseGetPos, then do a PixelSearch where the mouse is, but that's not what that code does.

Code: Select all

	ToolTip, click first
	KeyWait, LButton, D
	MouseGetPos, X1, Y1
	PixelGetColor R1, %MouseX1%, %MouseY1% ; <-- Unset  variables
	KeyWait, LButton, U
	ToolTip
	return
Valhalla188
Posts: 4
Joined: 15 Apr 2019, 19:56

Re: Issues with pixel comparing

19 Apr 2019, 00:38

OMG thank you... I feel so dumb, i copied the code and never changed the variable! -.-

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 28 guests