loop, break and errorlevel

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sebbulon
Posts: 47
Joined: 16 Sep 2020, 12:02

loop, break and errorlevel

Post by sebbulon » 23 Jan 2022, 05:09

Hello, i have a code where i want to do a loop 27 times (which adds up to somewhere between 8-10 seconds). In the loop i want to pixelsearch, if the pixel is found (errorlevel=0) i want to restart the loop (break+return for example), if the pixel is not found in ANY of the 27 loops i want to mousemove and click somewhere else. My only problem is that i don't know how to do "one" errorlevel=1 for all the 27 loops, the code down below does not work since there is no matching if due to the bracket before last row.

Code: Select all

loop, 27 {
sleep s1 ;300-450 ms;
pixelsearch, px, py, 506, 197, 527, 65, 0x7A3D09, a, Fast RGB ;a is 0-4;
if (errorlevel = 0){
		break
}
}
else if (errorlevel = 1){;do some other stuff that is irrelevant here;}
Ive tried some other solutions but i cant seem to get it to work, "i have to" pixelsearch a quite big area and pixelgetcolor doesnt work for me, because it only searches one pixel(??). If there are any other approach to what i want to do or if there is some solution to my code above, i'd highly appreciate any help :)

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: loop, break and errorlevel

Post by mikeyww » 23 Jan 2022, 08:32

Code: Select all

try = 0
Loop {
 Sleep, 200
 PixelSearch,,, 506, 197, 527, 65, 0x7A3D09, 1, Fast RGB
 try := ErrorLevel ? try + 1 : 0
 ToolTip, %try%
} Until (try = 27)
ToolTip
Send Done
Return

sebbulon
Posts: 47
Joined: 16 Sep 2020, 12:02

Re: loop, break and errorlevel

Post by sebbulon » 23 Jan 2022, 10:12

mikeyww wrote:
23 Jan 2022, 08:32

Code: Select all

try = 0
Loop {
 Sleep, 200
 PixelSearch,,, 506, 197, 527, 65, 0x7A3D09, 1, Fast RGB
 try := ErrorLevel ? try + 1 : 0
 ToolTip, %try%
} Until (try = 27)
ToolTip
Send Done
Return
Thx for your response, although im not so sure how to change this for my case. Does row 5 mean that everytime errorlevel 1 happends it adds +1 to "try" variable? When i tested the script it worked cuz the try reseted to 0 quite often but i dont know how to change it :)

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: loop, break and errorlevel

Post by mikeyww » 23 Jan 2022, 10:20

Yep. If the script works, then why do you want to change it?

What the script does: searches; counts the tries; when pixel is found, resets the tries; when tries reach 27, it continues instead of looping. In other words, "In the loop i want to pixelsearch, if the pixel is found (errorlevel=0) i want to restart the loop, if the pixel is not found in ANY of the 27 loops..."
ErrorLevel is set to 0 if the color was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search.
In this case, "If ErrorLevel" means "If ErrorLevel is not zero".

sebbulon
Posts: 47
Joined: 16 Sep 2020, 12:02

Re: loop, break and errorlevel

Post by sebbulon » 23 Jan 2022, 13:57

mikeyww wrote:
23 Jan 2022, 10:20
Yep. If the script works, then why do you want to change it?

What the script does: searches; counts the tries; when pixel is found, resets the tries; when tries reach 27, it continues instead of looping. In other words, "In the loop i want to pixelsearch, if the pixel is found (errorlevel=0) i want to restart the loop, if the pixel is not found in ANY of the 27 loops..."
ErrorLevel is set to 0 if the color was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search.
In this case, "If ErrorLevel" means "If ErrorLevel is not zero".
Nvm, i just had to get to know some of the lines in the script, they where new to me. Thanks for your help.

Post Reply

Return to “Ask for Help (v1)”