Jump to content

Recommended Posts

Posted

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?

 

 

Posted

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

Posted (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 by PEscobar
  • Developers
Posted

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.
  :)

Posted (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 by Trong

Regards,
 

Posted

@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)

 

Posted

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)

 

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
×
×
  • Create New...