Page 1 of 1

Help with PixelGetColor Conflict

Posted: 06 Jun 2018, 13:48
by Xero-Kill
I am working on a very simple script that is working 99% so far, with only one minor issue.

Code: Select all

NumPad8::Suspend, Toggle
NumPad9::Reload

CoordMode, Pixel, Relative

NumPad2::
 
PixelSearch, TargetX, TargetY, 323, 316, 1047, 599, %color%, 15, Fast
MouseMove, %TargetX%, %TargetY%
Sleep 250
MouseClick
Return

Numpad3::

MouseGetPos, MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%
MsgBox Bobber color has been captured. %color%
Return

NumPad7::

CoordMode, Pixel, Screen

loop
{
PixelGetColor, thiscolor, 1831, 910
thiscolor := (thiscolor >> 16)
if (thiscolor = 0x33){
	Send, {NumPad2}
	Sleep, 1200
	Send, {NumPad1}	
	}
		
else {
	Sleep, 67
	}
	
}
return
So when I press NumPad3 it gets the pixel color at my cursor and stores it for use in the NumPad 2 hotkey so that when NumPad2 is pressed it seeks out pixels in the defined area. This works just fine unless I reload the script, which I do often, at which time it seems to revert to the PixelGetColor value that is stored hotkey NumPad7 because when NumPad 2 is depressed after a script reload, it always goes to the same green location in my designated area. What I would like is for the stored value of %color% to persist through a reload and should ideally only change when I call for a change to that value with NumPad3. Also, if there is any other general clean up that can be done, that would be appreciated too. I realize that the script is sloppy.

EDIT: Changed the code a little, I used a copy of an older version that didn't work.

Re: Help with PixelGetColor Conflict

Posted: 07 Jun 2018, 14:21
by brutus_skywalker
https://autohotkey.com/docs/commands/IniRead.htm
https://autohotkey.com/docs/commands/IniWrite.htm

Code: Select all

NumPad8::Suspend, Toggle
NumPad9::Reload

CoordMode, Pixel, Relative

NumPad2::
 If !color
   IniRead, color, %A_ScriptName%.ini, SectionColor, KeyColor
 
PixelSearch, TargetX, TargetY, 323, 316, 1047, 599, %color%, 15, Fast
MouseMove, %TargetX%, %TargetY%
Sleep 250
MouseClick
Return

Numpad3::

MouseGetPos, MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%
IniWrite, %color%, %A_ScriptName%.ini, SectionColor, KeyColor
MsgBox Bobber color has been captured. %color%
Return

NumPad7::

CoordMode, Pixel, Screen

loop
{
PixelGetColor, thiscolor, 1831, 910
thiscolor := (thiscolor >> 16)
if (thiscolor = 0x33){
	Send, {NumPad2}
	Sleep, 1200
	Send, {NumPad1}	
	}
		
else {
	Sleep, 67
	}
	
}
return
Also check out https://autohotkey.com/board/topic/3897 ... ix-search/.

Re: Help with PixelGetColor Conflict

Posted: 07 Jun 2018, 14:47
by Xero-Kill
Thank you so much! That is perfect! I would have never even considered the iniwrite function. I will read through the whole thing in a bit.