Jump to content

Recommended Posts

Posted (edited)

hi

here is some codes :

Func _name()
$x = PixelGetColor(x,y)
    If $x = 100 Then
        Send("{enter}")
        ExitLoop
    EndIf
EndFunc

i have to repeat some of code in my script so i add my own function

but cant use it cus have error cus use in fuction "ExitLoop"

Edited by Jack_10
  • Moderators
Posted

Well... There is no loop there is why your getting the error.

If you want to return from where you called it, then use Return 1 or something.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

Well... There is no loop there is why your getting the error.

If you want to return from where you called it, then use Return 1 or something.

Func _name()
$x = PixelGetColor(x,y)
    If $x = 100 Then
        Send("{enter}")
        Return ExitLoop
    EndIf
EndFunc

This will be ok ?

Posted

It wont exitloop, because there is no loop :)

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Posted (edited)

Func _name()
$x = PixelGetColor(x,y)
    If $x = 100 Then
        Send("{enter}")
        Return ExitLoop
    EndIf
EndFunc

This will be ok ?

It's hard to tell what will help you without knowing how you call the function, and what you want back from it as a return. If you only want to loop untill it sees the color and send enter, then return to the script where it was called, this works:

; This is the pixel you are interested in:
$CoordX = 200
$CoordY = 300

; Send ENTER when pixel is white
$TriggerColor = 0xFFFFFF ; White
_EnterOnColor($CoordX, $CoordY, $TriggerColor)

; Send ENTER again when pixel turns black
$TriggerColor = 0x000000 ; Black
_EnterOnColor($CoordX, $CoordY, $TriggerColor)


; Function to wait until a pixel matches a color, then send ENTER
Func _EnterOnColor($iX, $iY, $iColor)
     While 1
          If PixelGetColor($iX, $iY) = $iColor Then Return
          Sleep(100)
     WEnd
EndFunc  ;==> _EnterOnColor()

Cheers!

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
  • 2 weeks later...
Posted

It's hard to tell what will help you without knowing how you call the function, and what you want back from it as a return. If you only want to loop untill it sees the color and send enter, then return to the script where it was called, this works:

; This is the pixel you are interested in:
$CoordX = 200
$CoordY = 300

; Send ENTER when pixel is white
$TriggerColor = 0xFFFFFF ; White
_EnterOnColor($CoordX, $CoordY, $TriggerColor)

; Send ENTER again when pixel turns black
$TriggerColor = 0x000000 ; Black
_EnterOnColor($CoordX, $CoordY, $TriggerColor)
; Function to wait until a pixel matches a color, then send ENTER
Func _EnterOnColor($iX, $iY, $iColor)
     While 1
          If PixelGetColor($iX, $iY) = $iColor Then Return
          Sleep(100)
     WEnd
EndFunc  ;==> _EnterOnColor()

Cheers!

:)

thx for code but it is not exacly what i need

i have many multilevel loop in program like :

Do
   Do
      Do
          ...
              ...
              ...
          ...
      Until
   Until
Until

and wanna exitloop at different level of loop

its why i realy need to use ExitLoop in my function (wanna ExitLoop at one level up)

Posted

Copy the function into the loop and say ExitLoop.

Hint: You can go back $n number of loops by saying ExitLoop $n (ExitLoop 2, Exitloop 3, Exitloop 4)

yes i know but if i copy only function it wont work cus exitloop is in IF EndIf so cant do something like this :

;program

...

Do

_x()

ExitLoop

Until

...

Fun _x()

...

EndFunc

Posted

yes i know but if i copy only function it wont work cus exitloop is in IF EndIf so cant do something like this :

;program

...

Do

_x()

ExitLoop

Until

...

Fun _x()

...

EndFunc

Your psudo-code is getting so psudo it's losing all meaning. :)

You wouldn't ever use ExitLoop unconditionally like that. It would be more like:

; If _x() returns status in @error
Do
   _x()
   If @error Then ExitLoop
Until

;Or, if _x() returns 1 or 0 as status
Do
   If Not _x() Then ExitLoop
Until

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

Your psudo-code is getting so psudo it's losing all meaning. :)

You wouldn't ever use ExitLoop unconditionally like that. It would be more like:

; If _x() returns status in @error
Do
   _x()
   If @error Then ExitLoop
Until

;Or, if _x() returns 1 or 0 as status
Do
   If Not _x() Then ExitLoop
Until

:P

Yea ! u have nice idea

i think this should be ok now :

Do
   _x()
   If $z = true Then ExitLoop
Until


Func _x()
   $y = PixelGetColor(x,y)
      If $y = 100 Then
         Send("{enter}")
         $z = true
            Return $z
      EndIf
   $z = false
      Return $z
EndFunc
Posted

Yea ! u have nice idea

i think this should be ok now :

Do
   _x()
   If $z = true Then ExitLoop
Until
Func _x()
   $y = PixelGetColor(x,y)
      If $y = 100 Then
         Send("{enter}")
         $z = true
            Return $z
      EndIf
   $z = false
      Return $z
EndFunc
Close! You misunderstand the use of Return values. Unless $z is declared globaly somewhere else, it is local by default inside the function (which is a good thing - good practice to avoid global variables inside functions as much as possible). So when you leave the function to go back to your Do/Until loop, $z won't be usable. But since you put "Return $z" in there correctly, the value returned from _x() is what was in $z. So your Do loop only needs:

Do
   If _x() = true Then ExitLoop
Until

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

Close! You misunderstand the use of Return values. Unless $z is declared globaly somewhere else, it is local by default inside the function (which is a good thing - good practice to avoid global variables inside functions as much as possible). So when you leave the function to go back to your Do/Until loop, $z won't be usable. But since you put "Return $z" in there correctly, the value returned from _x() is what was in $z. So your Do loop only needs:

Do
   If _x() = true Then ExitLoop
Until

:)

right

thx

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...