Simple Script (newbie need Help)

Ask gaming related questions (AHK v1.1 and older)
User avatar
Lyns
Posts: 2
Joined: 27 Jan 2020, 04:24

Simple Script (newbie need Help)

27 Jan 2020, 05:20

Hi , i am new and still figuring it out and learning but i am a bit confused in the help file can someone help me how to code the pixel or color , what i want to know what is the right code to search for pixel color and run / stop lines and scripts this exactly what im trying to make, thanks hope someone can help me, been searching and reading too but cant get it to work.

Code: Select all

#SingleInstance, force
#ifWinActive, ahk_exe ""
SetWorkingDir %A_ScriptDir%
full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
#MaxThreadsPerHotkey 2
f8::
toggle = 1
while toggle {
	Send, {w down}
	Sleep 1000                                          <<<<<< batch 1
	Send, {w up}
	Sleep 1000
	Send, {z}
	Sleep 1000
	
        <<<<<<<<<<< (if the color that was set is visible  the line/script (batch 1)  keeps looping) 
        <<<<<<<<<< (if the color that was set is not visible anymore  the line/script (batch 1) stops)

        <<<<<<<<<< ( if the color become visible again run the next line or script ) (batch 2) keeps looping as long as visible if not visible anymore = stop

       Send, 1
       Sleep 500
       Send, 2
       Sleep 500                                                  <<<< batch  2
       Send, 3
       Sleep 500
    
        
}
return
[Mod edit: [code][/code] tags added]
Tcharr
Posts: 41
Joined: 25 Jan 2020, 15:38

Re: Simple Script (newbie need Help)

27 Jan 2020, 09:42

Nice timing. I just posted my usage of SearchPixel in a nearby thread: https://www.autohotkey.com/boards/viewtopic.php?f=18&t=14665

Code: Select all

;Color check
ColorCheck(){
	;Check for white pixels in area defined by coordinates (632, 931), (639, 931), (639, 938), and (632, 938).
		PixelSearch, Px, Py, 632, 931, 639, 938, 0xfefefe, 1, Fast
			if ErrorLevel
			    return false
			else
			    return true
}
Note that the pixels for which I was searching are not pure white, so I allowed a shade variance of ±1 for each of the RGB values, so my ColorCheck() returns true for values from 0xfdfdfd to 0xffffff.

To run your selections, you could then write something like:

Code: Select all

While Colorcheck(){
	If FirstColor
		Subroutine1
	else
		Subroutine2
}
User avatar
Lyns
Posts: 2
Joined: 27 Jan 2020, 04:24

Re: Simple Script (newbie need Help)

27 Jan 2020, 21:17

thanks bro but i think i messed up there something wrong here can you figure it out for me, so i can learn from mistakes :)

Code: Select all

#SingleInstance, force
#ifWinActive, ahk_exe Test.exe
SetWorkingDir %A_ScriptDir%
full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
#MaxThreadsPerHotkey 2
f8::
toggle = 1
;Color check
ColorCheck(){
	
	PixelSearch, Px, Py, 308, 158, 308, 158, 0xff4700, 1, Fast
		
		if  ErrorLevel
			return false
		else
			 return true

}
While Colorcheck(){
	If  0xff4700
		send {w}
	else
		Send {a}
}

return
f9::pause
[Mod edit: [code][/code] tags added. Please start to use them yourself!]
Tcharr
Posts: 41
Joined: 25 Jan 2020, 15:38

Re: Simple Script (newbie need Help)

28 Jan 2020, 07:44

The mistake was mine. I was not clear about the meaning of FirstColor. I just meant that to be a placeholder for a flag that shows whether it is the first time that Colorcheck returned 'true' (found your color). If it is the first time, the run the first macro; if it is the second or subsequent time finding that color, then run the second.

So you need to make a flag variable initialized to 'true' at the beginning. When Colorcheck first returns 'true', you run your first macro and also set the flag to 'false', since any other findings of that color will no longer be first.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 45 guests