# Problem with If loop

## Recommended Posts

Hello community,

I have little problem in the loops. For short, these few loops are checking color of pixels and little squares pixel colors sums. If they both isn't that color/sum program MouseClick somewhere. Pixels are spreaded as matrix 5x8. It starts checking from the bottom right corner and goes left side, after that line it goes one line up and checks it again.

The problem I'm getting is that the first check (the 8th line, 5th element) always being pressed, when both of expressions are negative. I tried doing it apart and it looks like they should work fine. But i can't understand why the very first loop goes inside of "If" statement when he should skip it. All other times loop does everything fine. Any ideas why it happens?

```\$i=8
\$j=5
\$ii=0

Do
\$j=5
\$i=\$i-1
Do
\$j=\$j-1
If  PixelGetColor(1117+\$j*43, 183+\$i*43) <> 0xFFFBAD And PixelChecksum(1106+\$j*43, 172+\$i*43, 1106+29+\$j*43, 172+29+\$i*43) <> FileReadLine(\$file, \$i*5+\$j+1) Then
MouseClick("left", 1104+14+\$j*43, 170+14+\$i*43)
Sleep(300)
MouseClick("left", 445, 435)
Sleep(300)
\$ii=\$ii+1
If \$ii=6 Then
Sleep(200)
MouseClick("left", 480, 445)
Sleep(300)
\$ii=0
EndIf
EndIf
Until \$j=0
Until \$i=0```
Edited by XLimas

##### Share on other sites

Hello community,

I have little problem in the loops. For short, these few loops are checking color of pixels and little squares pixel colors sums. If they both isn't that color/sum program MouseClick somewhere. Pixels are spreaded as matrix 5x8. It starts checking from the bottom right corner and goes left side, after that line it goes one line up and checks it again.

The problem I'm getting is that the first check (the 8th line, 5th element) always being pressed, when both of expressions are negative. I tried doing it apart and it looks like they should work fine. But i can't understand why the very first loop goes inside of "If" statement when he should skip it. All other times loop does everything fine. Any ideas why it happens?

```\$i=8
\$j=5
\$ii=0

Do
\$j=5
\$i=\$i-1
Do
\$j=\$j-1
If  PixelGetColor(1117+\$j*43, 183+\$i*43) <> 0xFFFBAD And PixelChecksum(1106+\$j*43, 172+\$i*43, 1106+29+\$j*43, 172+29+\$i*43) <> FileReadLine(\$file, \$i*5+\$j+1) Then
MouseClick("left", 1104+14+\$j*43, 170+14+\$i*43)
Sleep(300)
MouseClick("left", 445, 435)
Sleep(300)
\$ii=\$ii+1
If \$ii=6 Then
Sleep(200)
MouseClick("left", 480, 445)
Sleep(300)
\$ii=0
EndIf
EndIf
Until \$j=0
Until \$i=0```
Values read from a file will be strings and need conversion to integers for compares. Also, the awkward Do/Until structure was not required. I also added some intermediate variables. They aren't required, but make debugging much easier:
```Global \$ii = 0, \$iPixColor, \$iChkSum, \$iPixColor, \$iChkSum, \$iTestSum
For \$i = 7 To 0 Step -1
For \$j = 4 To 0 Step -1
\$iPixColor = PixelGetColor(1117 + \$j * 43, 183 + \$i * 43)
\$iChkSum = PixelChecksum(1106 + \$j * 43, 172 + \$i * 43, 1106 + 29 + \$j * 43, 172 + 29 + \$i * 43)
\$iTestSum = Int(FileReadLine(\$file, \$i * 5 + \$j + 1))
ConsoleWrite("Debug:  \$i = " & \$i & ", \$j = " & \$j & ", \$iPixColor = " & \$iPixColor & _
", \$iChkSum = " & \$iChkSum & ", \$iTestSum = " & \$iTestSum & @LF)
If  (\$iPixColor <> 0xFFFBAD) And (\$iChkSum <> \$iTestSum) Then
MouseClick("left", 1104 + 14 + \$j * 43, 170 + 14 + \$i * 43)
Sleep(300)
MouseClick("left", 445, 435)
Sleep(300)
\$ii += 1
If \$ii = 6 Then
Sleep(200)
MouseClick("left", 480, 445)
Sleep(300)
\$ii = 0
EndIf
EndIf
Next
Next```

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

## Create an account

Register a new account

×

• Wiki

• Back

• Git