Jump to content
PEscobar

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

Recommended Posts

PEscobar

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?

 

 

Share this post


Link to post
Share on other sites
PEscobar

That made it open the file again, but now it stops the rest of the script. There was more after it, I just shortened it.

Share this post


Link to post
Share on other sites
InunoTaishou

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

Share this post


Link to post
Share on other sites
PEscobar

I tried both of your solutions and it still only runs once. 

Share this post


Link to post
Share on other sites
Jos

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

Jos 


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
VIP
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,
 

Share this post


Link to post
Share on other sites
PEscobar

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

Share this post


Link to post
Share on other sites
Jos

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 


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
PEscobar
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

Share this post


Link to post
Share on other sites
VIP
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,
 

Share this post


Link to post
Share on other sites
kcvinu

@PEscobar ,

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

 


My Contributions

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)

 

Share this post


Link to post
Share on other sites
PEscobar

Oops I copied that from an older version, I fixed that already and make it selectgreen()

Share this post


Link to post
Share on other sites
kcvinu

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

 


My Contributions

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)

 

Share this post


Link to post
Share on other sites
PEscobar

I found a simple solution.

I just put the search for the colour into the function "OpenPng()"

Then I put "If @error Then OpenPng()"

 

Share this post


Link to post
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

  • Similar Content

    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • Aleksandar
      By Aleksandar
      So can anyone help me ? I need to restart program when condition is not met ...

    • krasnoshtan
      By krasnoshtan
      Hello forum users!
      At some point I had a need to restart my script. Is it possible to do this with autoit or do I need to connect additional scripts like .cmd or .bat?
      For example: i have only script.au3 and it's running. Wich code shoud i use to exit from the script and start it again?
    • MrCheese
      By MrCheese
      Hi guys,
       
      Wondering, is there a better way, likely to use 'for...next' to add a letter to each range, by moving right -> along a range of columns in excel.
      I currently use this, but its clunky.
      If $run = 1 Then $range = "B6:B41" If $run = 2 Then $range = "C6:C41" If $run = 3 Then $range = "D6:D41" If $run = 4 Then $range = "E6:E41" If $run = 5 Then $range = "F6:F41" If $run = 6 Then $range = "G6:G41" If $run = 7 Then $range = "H6:H41" If $run = 8 Then $range = "I6:I41" If $run = 9 Then $range = "J6:J41" If $run = 10 Then $range = "K6:K41" If $run = 11 Then $range = "L6:L41" If $run = 12 Then $range = "M6:M41" If $run = 13 Then $range = "N6:N41" If $run = 14 Then $range = "O6:O41" If $run = 15 Then $range = "P6:P41" If $run = 16 Then $range = "Q6:Q41" If $run = 17 Then $range = "R6:R41" If $run = 18 Then $range = "S6:S41" If $run = 19 Then $range = "T6:T41" If $run = 20 Then $range = "U6:U41" If $run = 21 Then $range = "V6:V41" If $run = 22 Then $range = "W6:W41" If $run = 23 Then $range = "X6:X41" If $run = 24 Then $range = "Y6:Y41" If $run = 25 Then $range = "Z6:Z41" If $run = 26 Then $range = "AA6:AA41" If $run = 27 Then $range = "AB6:AB41" If $run = 28 Then $range = "AC6:AC41" If $run = 29 Then $range = "AD6:AD41" If $run = 30 Then $range = "AE6:AE41" If $run = 31 Then $range = "AF6:AF41" If $run = 32 Then $range = "AG6:AG41" If $run = 33 Then $range = "AH6:AH41" If $run = 34 Then $range = "AI6:AI41" If $run = 35 Then $range = "AJ6:AJ41" If $run = 36 Then $range = "AK6:AK41" If $run = 37 Then $range = "AL6:AL41" If $run = 38 Then $range = "AM6:AM41" If $run = 39 Then $range = "AN6:AN41" If $run = 40 Then $range = "AO6:AO41" If $run = 41 Then $range = "AP6:AP41" If $run = 42 Then $range = "AQ6:AQ41" If $run = 43 Then $range = "AR6:AR41" If $run = 44 Then $range = "AS6:AS41" If $run = 45 Then $range = "AT6:AT41" If $run = 46 Then $range = "AU6:AU41" If $run = 47 Then $range = "AV6:AV41" If $run = 48 Then $range = "AW6:AW41" If $run = 49 Then $range = "AX6:AX41" If $run = 50 Then $range = "AY6:AY41"  
      Normally, if it was going down the rows, i'd use this:
       
      For $i = 0 To UBound($iRowCount) - 1 $row = $i + 1 $range = "B"&$row&":B"&$row+1 Next  
      so something like this, but i don't know how to code sequential columns:
      For $i = 0 To UBound($iColCount) - 1 $col = $i + 1 $range = $col&"1:"&$col&"40" Next  
      If I don't make sense, let me know.
      Any help would be great. thanks
    • KING_NK
      By KING_NK
      #RequireAdmin
      Global $x=0
      Global $y=0
      Func Start()
      While 1
      AutoItSetOption('MouseCoordMode',0)
      AutoItSetOption('SendKeyDelay',10)
      WinActivate('XXX')
      MouseClick('Primary',852,62,1,10)
      sleep(2200)
      MouseClick('Primary',880,196,1,10)
      Send('260',0)      -----------------------> $a as 260
      MouseClick('Primary',880,196,1,0)
      sleep(2200)
      MouseClick('Primary',1019,194,1,10)
      Sleep(2200)
      Send('98',0) ------------------------->$b as 98
      sleep(1000)
      Wend
      EndFunc
       
       
      I want to use Different number in every loop in the place of $a and  $b.
      Is it possble?If it possible Kindly help me
×