Jack_10 Posted September 9, 2006 Share Posted September 9, 2006 (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 September 9, 2006 by Jack_10 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 9, 2006 Moderators Share Posted September 9, 2006 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. Link to comment Share on other sites More sharing options...
Jack_10 Posted September 9, 2006 Author Share Posted September 9, 2006 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 ? Link to comment Share on other sites More sharing options...
AzKay Posted September 9, 2006 Share Posted September 9, 2006 It wont exitloop, because there is no loop # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
Jack_10 Posted September 9, 2006 Author Share Posted September 9, 2006 It wont exitloop, because there is no loop so how have to i change code to be ok ? Link to comment Share on other sites More sharing options...
Developers Jos Posted September 9, 2006 Developers Share Posted September 9, 2006 so how have to i change code to be ok ?Return 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 More sharing options...
PsaltyDS Posted September 9, 2006 Share Posted September 9, 2006 (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 September 9, 2006 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 Link to comment Share on other sites More sharing options...
Jack_10 Posted September 19, 2006 Author Share Posted September 19, 2006 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) Link to comment Share on other sites More sharing options...
jvanegmond Posted September 19, 2006 Share Posted September 19, 2006 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) github.com/jvanegmond Link to comment Share on other sites More sharing options...
Jack_10 Posted September 19, 2006 Author Share Posted September 19, 2006 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() ExitLoopUntil...Fun _x()...EndFunc Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 19, 2006 Share Posted September 19, 2006 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 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 Link to comment Share on other sites More sharing options...
Jack_10 Posted September 19, 2006 Author Share Posted September 19, 2006 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 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 19, 2006 Share Posted September 19, 2006 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 Link to comment Share on other sites More sharing options...
Jack_10 Posted September 19, 2006 Author Share Posted September 19, 2006 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 Link to comment Share on other sites More sharing options...
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