I need help with my if statments Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Phoenix_Blu
Posts: 6
Joined: 13 Nov 2020, 14:10

I need help with my if statments

13 Nov 2020, 14:17

I am getting error after error with my script. can someone please help me with this. and tell me my mistakes. if possible can you also help me fix it

Code: Select all

#p::ExitApp
Loop
{

Sleep 20000
Send {Tab down}

PixelGetColor,col,46,105,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else if
 {
Sleep 5
}


PixelGetColor,col,46,124,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,143,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,162,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,180,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,197,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}







PixelGetColor,col,46,216,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}










PixelGetColor,col,46,234,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,251,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,169,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,287,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}









PixelGetColor,col,46,307,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,324,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,342,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,360,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,378,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,396,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,413,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 5
}

PixelGetColor,col,46,431,RGB ;get pixel at 10,10 in RedGreenBlue format
if (col == 0x5f5f5f) { ;if color = 0x5f5f5f hex for Grey
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
 else 
 {
Sleep 500
}

Sleep 500
Send {Tab up}

Sleep 4000
Sleep 300
Send /
Sleep 300
Send w
Sleep 300
Send a
Sleep 300
Send r
Sleep 300
Send p
Sleep 300
Send {space}
Sleep 300
Send p
Sleep 300
Send a
Sleep 300
Send r
Sleep 300
Send k
Sleep 300
Send {enter}
Sleep 10000
Sleep 300
Send /
Sleep 300
Send w
Sleep 300
Send a
Sleep 300
Send r
Sleep 300
Send p
Sleep 300
Send {space}
Send e
Sleep 300
Send n
Sleep 300
Send d
Sleep 300
Send {enter}
return

}

return ;return script to idle

Sleep 5000
Send {Tab up}
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: I need help with my if statments

13 Nov 2020, 14:25

I didn't test anything but try going over your script and remove the { on these lines

Code: Select all

if (col == xxxxxxxx) { 
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: I need help with my if statments  Topic is solved

13 Nov 2020, 14:26

I agree. You have lots of syntax errors. For example, If should not be followed by {. You have multiple braces in a row (not always a problem, but perhaps unintended in your script), and so on. Start with a very small part of your script, and delete the rest, until you get it right. Breaking down a script in that way is an approach to debugging it.

Read the documentation about auto-execute section. That is a section at the top of a script, before hotkeys and hotstrings, in cases where you want a block of code to run unconditionally.
Phoenix_Blu
Posts: 6
Joined: 13 Nov 2020, 14:10

Re: I need help with my if statments

13 Nov 2020, 14:29

Thanks. it helped. I made that mistake once, and copy pasted 19 times. i also put a popup box by accident. Now how do i close a post? im still new
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: I need help with my if statments

13 Nov 2020, 14:35

Phoenix_Blu wrote:
13 Nov 2020, 14:29
Now how do i close a post? im still new
Just leave it as it is. You already marked an answer. That's fine.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: I need help with my if statments

14 Nov 2020, 02:08

Phoenix_Blu wrote:
13 Nov 2020, 14:17
I am getting error after error with my script. can someone please help me with this. and tell me my mistakes. if possible can you also help me fix it

Code: Select all

if (col == 0x5f5f5f) {
{	msgbox % "Color = " col " `nThis color is Grey"
	ExitApp
}
Possibly, you are having confusion about which indenting style that you want to use or are in confusion about what is a function. In terms of style, among the most common are Allman and K&R style/one true brace style. Personally, I advocate for Allman or a variation of it called Horstmann style (https://en.wikipedia.org/wiki/Indentation_style#Horstmann_style). The reason why is that Allman/Horstmann provides better visual clarity in reading code, and helps reduce mistakes when writing code. The issue about reading clarity becomes even more important for large programs (to reduce eye strain) or reading back code months later, where your memory as to what you did gets fuzzy.

Note- examples below are pseudo-code and functions:

K&R style/one true brace

Code: Select all

Checknegative(x) {
    if (x < 0) {
        Puts("Negative")
    } else {
        NonNegative(x)
    }
}
Allman/Horstmann

Code: Select all

Checknegative(x)
{
	if (x < 0) 
	{
        		Puts("Negative")
	} 
	else 
	{
        		NonNegative(x)
	}
}
You will see both styles, so you should be able to read both, in case you are looking at somebody else's code. K&R style/one true brace style tends to be a bit more prevalent, but so are the careless coding errors. Also, here is an AutoHotkey thread on the subject.
https://www.autohotkey.com/boards/viewtopic.php?t=48809
(Allman style v. K&R style/one true brace style)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot], RandomBoy and 408 guests