Jump to content

How to restart a loop if there is an @error?


 Share

Recommended Posts

So I made a loop beginning with while $e = 1. It opens a file and searches for a colour in the file, if the colour isn't there $e = 2 so the loop ends and restarts. Instead of that, the loop runs once and then just stops completely, even if the colour is there. 

Here is what it looks like basically.

While $e = 1 

    OpenPng()

      $aCoord = PixelSearch ($left, $top, $right, $bottom, 0x3B5E05, 0)
      If @error Then $e = 2

WEnd

How do I make it so the loop restarts if the colour isn't there, but it continues normally if the colour is there?

 

 

Link to comment
Share on other sites

Move OpenPng() above the Do then

Do...Until will always execute everything between the Do and Until at least once, no matter what. Then it's going to test against the condition after Until (the Not @Error). If there was an error in the pixel search then it's going to continue to execute the pixelsearch until it doesn't fail. Once it succeeds it will do everything after the do...until

Link to comment
Share on other sites

  • Developers

My Crystal ball isn't telling me much so the information will have to come from you to understand what you are trying. ;)

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Local $aCoord
Local $sColor = 0x3B5E05
Local $left = 0, $top = 0, $right = @DesktopWidth, $bottom = @DesktopHeight
While 1
    $aCoord = PixelSearch($left, $top, $right, $bottom, $sColor)
    If @error Or Not IsArray($aCoord) Then ContinueLoop
;~  OpenPng()
;   MouseClick($aCoord[0], $aCoord[1])
;   Sleep(100)
WEnd
Edited by Trong

Regards,
 

Link to comment
Share on other sites

So the script opens a file and then searches for a colour. If the colour is there, then I want the loop to continue as normal, if the colour isn't there I want the loop to restart. I also want it to run more than once

Edited by PEscobar
Link to comment
Share on other sites

  • Developers

So the script opens a file and then searches for a colour. If the colour is there, then I want the loop to continue as normal, if the colour isn't there I want the loop to restart. I also want it to run more than once

These are words, not code, so open for interpretation.
Please post a code snippet that doesn't work yet and what the issue is.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

While 1
    OpenPng()
    sleep(250)
    $coord1 = PixelSearch ($left, $top, $right, $bottom, 0x432D1E, 1)
    If @error Then ContinueLoop
    If not @error Then Selectgreen()
WEnd

It will open the picture and then select the colour once, but it doesn't keep doing it like a normal loop would. It only goes through it once.

Edited by PEscobar
Link to comment
Share on other sites

Opt("TrayAutoPause", 0)

Local $sColor = "0x3B5E05"
Local $pLeft = 0, $pTop = 0, $pRight = @DesktopWidth, $pBottom = @DesktopHeight
Local $sPNG = @ScriptDir & "\image.png"
HotKeySet("{ESC}", "_Exit")
_OpenPNG()
Local $aCoord
While 1
    ToolTip("")
;~  _OpenPNG()
    $aCoord = PixelSearch($pLeft, $pTop, $pRight, $pBottom, $sColor)
    If @error Or Not IsArray($aCoord) Then ContinueLoop
    ToolTip($sColor & " color found at position " & $aCoord[0] & " " & $aCoord[1])
    Sleep(250)
WEnd

Func _OpenPNG()
    ShellExecute($sPNG)
EndFunc   ;==>_OpenPNG

Func _Exit()
    Exit ToolTip("")
EndFunc   ;==>_Exit
Edited by Trong

Regards,
 

Link to comment
Share on other sites

@PEscobar ,

I am assuming that "Select" is your function. But SciTE is considering it as "Select" keyword.

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

And you don't need to use 2 If statements. You can use ElseIf 

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...