# Error If/Else

## Recommended Posts

```\$Class = 2

;Section 1
If \$Class = 1 Then
Do
\$Color1 = Pixelgetcolor(506,392)
\$Color2 = Pixelgetcolor(871,561)
\$Color3 = Pixelgetcolor(286,537)
If \$Color3 = "527368" Then MouseClick ( "left" , 167, 472 , 1 , 1  )
If \$Color1 = "0" Then MouseClick ( "left" , 649, 424 , 1 , 1  )
Until \$Color2 = "0"
Sleep(500)
MouseClick ( "left" , 510, 408 , 1 , 1  )

If \$Stack < 5 then
Do
\$ColorEnd = Pixelgetcolor(249,140)
sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 then
\$Stack = 0
sleep(2000) ; End of Section 1

Else ; Problem HERE

; Section 2
If \$Class = 2 Then

Do
\$Color1 = Pixelgetcolor(506,392)
\$Color2 = Pixelgetcolor(871,561)
\$Color3 = Pixelgetcolor(286,537)
\$Color4 = Pixelgetcolor(606,440)
If \$Color3 = "527368" Then MouseClick ( "left" , 167, 472 , 1 , 1  )
If \$Color4 = "0" Then MouseClick ( "left" , 608, 425 , 1 , 1  )
If \$Color1 = "0" Then MouseClick ( "left" , 503, 420 , 1 , 1  )
Until \$Color2 = "0"
Sleep(500)
MouseClick ( "left" , 510, 408 , 1 , 1  )
If \$Stack < 5 then
Do
\$ColorEnd = Pixelgetcolor(249,140)
sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 then
\$Stack = 0
sleep(2000) ; End of Section 2
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf

Exit```

Ok here's the problem. The script pass over the section 2 because the first If is not linked to the Else between the 2 sections. If \$Class = 2 then the script Exit straight away, he dont do the section 2. There's alot of If,Else,Do,Until in there so I dont know where the problem come from.

Edited by J0ker

##### Share on other sites

You have and extra "Endif" in your script. If you use the syntax checking in SciTE, you would see the error

```\$Class = 2
\$Stack = 0
;Section 1
If \$Class = 1 Then
Do
\$Color1 = PixelGetColor(506, 392)
\$Color2 = PixelGetColor(871, 561)
\$Color3 = PixelGetColor(286, 537)
If \$Color3 = "527368" Then MouseClick("left", 167, 472, 1, 1)
If \$Color1 = "0" Then MouseClick("left", 649, 424, 1, 1)
Until \$Color2 = "0"
Sleep(500)
MouseClick("left", 510, 408, 1, 1)

If \$Stack < 5 Then
Do
\$ColorEnd = PixelGetColor(249, 140)
Sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 Then
\$Stack = 0
Sleep(2000) ; End of Section 1

Else ; Problem HERE

; Section 2
If \$Class = 2 Then

Do
\$Color1 = PixelGetColor(506, 392)
\$Color2 = PixelGetColor(871, 561)
\$Color3 = PixelGetColor(286, 537)
\$Color4 = PixelGetColor(606, 440)
If \$Color3 = "527368" Then MouseClick("left", 167, 472, 1, 1)
If \$Color4 = "0" Then MouseClick("left", 608, 425, 1, 1)
If \$Color1 = "0" Then MouseClick("left", 503, 420, 1, 1)
Until \$Color2 = "0"
Sleep(500)
MouseClick("left", 510, 408, 1, 1)
If \$Stack < 5 Then
Do
\$ColorEnd = PixelGetColor(249, 140)
Sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 Then
\$Stack = 0
Sleep(2000) ; End of Section 2
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf

Exit```

8)

##### Share on other sites

Sorry the extra EndIf was coming from another part of my script so I should not have posted it here. What you just posted is my actual script.

```\$Class = 2
\$Stack = 0
;Section 1
If \$Class = 1 Then
Do
\$Color1 = PixelGetColor(506, 392)
\$Color2 = PixelGetColor(871, 561)
\$Color3 = PixelGetColor(286, 537)
If \$Color3 = "527368" Then MouseClick("left", 167, 472, 1, 1)
If \$Color1 = "0" Then MouseClick("left", 649, 424, 1, 1)
Until \$Color2 = "0"
Sleep(500)
MouseClick("left", 510, 408, 1, 1)

If \$Stack < 5 Then
Do
\$ColorEnd = PixelGetColor(249, 140)
Sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 Then
\$Stack = 0
Sleep(2000) ; End of Section 1

Else ; Problem HERE

; Section 2
If \$Class = 2 Then

Do
\$Color1 = PixelGetColor(506, 392)
\$Color2 = PixelGetColor(871, 561)
\$Color3 = PixelGetColor(286, 537)
\$Color4 = PixelGetColor(606, 440)
If \$Color3 = "527368" Then MouseClick("left", 167, 472, 1, 1)
If \$Color4 = "0" Then MouseClick("left", 608, 425, 1, 1)
If \$Color1 = "0" Then MouseClick("left", 503, 420, 1, 1)
Until \$Color2 = "0"
Sleep(500)
MouseClick("left", 510, 408, 1, 1)
If \$Stack < 5 Then
Do
\$ColorEnd = PixelGetColor(249, 140)
Sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 Then
\$Stack = 0
Sleep(2000) ; End of Section 2
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf

Exit```

It's still skipping the section 2. Anyone know why?

Edited by J0ker

##### Share on other sites

it is the "corrected" script i pasted

.... also per help

PixelGetColor ( x , y )

Parameters

x x coordinate of pixel. y y coordinate of pixel.

Return Value

Success: Returns decimal value of pixel's color.

Failure: Returns -1 if invalid coordinates.

Until \$Color... = "0"

you wont get a "0"

8)

BTW... if invalid coordinates.. ??? ( not quite sure what that means )

Edited by Valuater

##### Share on other sites

it is the "corrected" script i pasted

Yes this script dont get any errors if I run the syntax checker but it's still skip the section 2. There's something not working in my Else/If.

\$Color... = "0"

This is working I'm 100% sure, 0 = Black. I tried it. If I put \$Class = 1, it work perfectly.

My pixelgetcolor variables are working, there's no problem with them. My script is based on that and I have 500 lines ++ of script. Only this part of my script isnt working because it skip the section 2.

Edited by J0ker

##### Share on other sites

if that is the case then maybe...

```\$Class = 2

;Section 1
If \$Class = 1 Then
Do
\$Color1 = PixelGetColor(506, 392)
\$Color2 = PixelGetColor(871, 561)
\$Color3 = PixelGetColor(286, 537)
If \$Color3 = "527368" Then MouseClick("left", 167, 472, 1, 1)
If \$Color1 = "0" Then MouseClick("left", 649, 424, 1, 1)
Until \$Color2 = "0"
Sleep(500)
MouseClick("left", 510, 408, 1, 1)

If \$Stack < 5 Then
Do
\$ColorEnd = PixelGetColor(249, 140)
Sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 Then
\$Stack = 0
Sleep(2000) ; End of Section 1
EndIf ; Problem HERE
EndIf
EndIf
; Section 2
If \$Class = 2 Then

Do
\$Color1 = PixelGetColor(506, 392)
\$Color2 = PixelGetColor(871, 561)
\$Color3 = PixelGetColor(286, 537)
\$Color4 = PixelGetColor(606, 440)
If \$Color3 = "527368" Then MouseClick("left", 167, 472, 1, 1)
If \$Color4 = "0" Then MouseClick("left", 608, 425, 1, 1)
If \$Color1 = "0" Then MouseClick("left", 503, 420, 1, 1)
Until \$Color2 = "0"
Sleep(500)
MouseClick("left", 510, 408, 1, 1)
If \$Stack < 5 Then
Do
\$ColorEnd = PixelGetColor(249, 140)
Sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 Then
\$Stack = 0
Sleep(2000) ; End of Section 2
EndIf
EndIf
EndIf

Exit```

##### Share on other sites

Your problem is that you have an If \$Class = 2 inside an If \$Class = 1. \$Class will never be 2 inside that particular if..then statement. Try reformatting your if..then statements a little.

##### Share on other sites

if that is the case then maybe...

```\$Class = 2
;Section 1
If \$Class = 1 Then
Do
\$Color1 = PixelGetColor(506, 392)
\$Color2 = PixelGetColor(871, 561)
\$Color3 = PixelGetColor(286, 537)
If \$Color3 = "527368" Then MouseClick("left", 167, 472, 1, 1)
If \$Color1 = "0" Then MouseClick("left", 649, 424, 1, 1)
Until \$Color2 = "0"
Sleep(500)
MouseClick("left", 510, 408, 1, 1)

If \$Stack < 5 Then
Do
\$ColorEnd = PixelGetColor(249, 140)
Sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 Then
\$Stack = 0
Sleep(2000) ; End of Section 1
EndIf ; Problem HERE
EndIf
EndIf
; Section 2
If \$Class = 2 Then

Do
\$Color1 = PixelGetColor(506, 392)
\$Color2 = PixelGetColor(871, 561)
\$Color3 = PixelGetColor(286, 537)
\$Color4 = PixelGetColor(606, 440)
If \$Color3 = "527368" Then MouseClick("left", 167, 472, 1, 1)
If \$Color4 = "0" Then MouseClick("left", 608, 425, 1, 1)
If \$Color1 = "0" Then MouseClick("left", 503, 420, 1, 1)
Until \$Color2 = "0"
Sleep(500)
MouseClick("left", 510, 408, 1, 1)
If \$Stack < 5 Then
Do
\$ColorEnd = PixelGetColor(249, 140)
Sleep(100)
Until \$ColorEnd = "0"
\$Stack = \$Stack + 1
Else
If \$Stack = 5 Then
\$Stack = 0
Sleep(2000) ; End of Section 2
EndIf
EndIf
EndIf
Exit```
It work ! Thanks Valuater Edited by J0ker

Welcome

8)

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...