PEscobar Posted January 10, 2016 Posted January 10, 2016 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 = 2WEndHow do I make it so the loop restarts if the colour isn't there, but it continues normally if the colour is there?
InunoTaishou Posted January 10, 2016 Posted January 10, 2016 Do OpenPng() $aCoord = PixelSearch ($left, $top, $right, $bottom, 0x3B5E05, 0) Until (Not @error)
PEscobar Posted January 10, 2016 Author Posted January 10, 2016 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.
InunoTaishou Posted January 10, 2016 Posted January 10, 2016 Move OpenPng() above the Do thenDo...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
Developers Jos Posted January 10, 2016 Developers Posted January 10, 2016 Look at ContinueLoop.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.
PEscobar Posted January 10, 2016 Author Posted January 10, 2016 I tried both of your solutions and it still only runs once.
Developers Jos Posted January 10, 2016 Developers Posted January 10, 2016 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.
Trong Posted January 10, 2016 Posted January 10, 2016 (edited) 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 January 10, 2016 by Trong Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal
PEscobar Posted January 10, 2016 Author Posted January 10, 2016 (edited) 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 January 10, 2016 by PEscobar
Developers Jos Posted January 10, 2016 Developers Posted January 10, 2016 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 onceThese 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.
PEscobar Posted January 10, 2016 Author Posted January 10, 2016 (edited) While 1 OpenPng() sleep(250) $coord1 = PixelSearch ($left, $top, $right, $bottom, 0x432D1E, 1) If @error Then ContinueLoop If not @error Then Selectgreen() WEndIt 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 January 10, 2016 by PEscobar
Trong Posted January 10, 2016 Posted January 10, 2016 (edited) 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 January 10, 2016 by Trong Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal
kcvinu Posted January 10, 2016 Posted January 10, 2016 @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)
PEscobar Posted January 10, 2016 Author Posted January 10, 2016 Oops I copied that from an older version, I fixed that already and make it selectgreen()
kcvinu Posted January 10, 2016 Posted January 10, 2016 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)
PEscobar Posted January 10, 2016 Author Posted January 10, 2016 I found a simple solution.I just put the search for the colour into the function "OpenPng()"Then I put "If @error Then OpenPng()"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now