Xibalba Posted January 19, 2014 Posted January 19, 2014 (edited) Maybe I'm just too tired, but I came across this and didn't quite know how to solve it at once: Func myFunc() If $something Then StopTimer() Return 0 ElseIf $somethingElse Then StopTimer() Return 1 Else StopTimer() Return 2 EndIf EndFunc My idea was to make a return function to get rid of all the StopTimer() lines: Func MyFunc_Return($val) StopTimer() Return $val EndFunc And then use it like so: If $something Then MyFunc_Return(0) ElseIf $somethingElse Then... But then the problem persists of course - how do we get MyFunc to actually return and exit the function? In my real script there is lots of returns... Edit: bleh typo... how do I change topic title? Edited January 19, 2014 by Xibalba
l3ill Posted January 19, 2014 Posted January 19, 2014 Click Edit then on Use Full Editor You should be able to change title there. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
mikell Posted January 19, 2014 Posted January 19, 2014 Why not simply Func myFunc() StopTimer() If $something Then Return 0 ElseIf $somethingElse Then Return 1 Else Return 2 EndIf EndFunc ?
Xibalba Posted January 19, 2014 Author Posted January 19, 2014 (edited) mikell, Lots of more code is run inside each If statement. Hence the need to stop the timer just prior to returning. Edited January 19, 2014 by Xibalba
mikell Posted January 19, 2014 Posted January 19, 2014 (edited) Then I'm afraid there is no miracle solution and you'll have to go this way Func myFunc() Local $value If $something Then ; lot of code $value = 0 ElseIf $somethingElse Then ; lot of code $value = 1 Else ; lot of code $value = 2 EndIf StopTimer() Return $value EndFunc Edited January 19, 2014 by mikell
Solution AlmarM Posted January 19, 2014 Solution Posted January 19, 2014 I'm not entirely sure what you want, but is this something you need? Global $bSomething = False Global $bSomethingElse = (Not $bSomething) MyFunc() Func MyFunc() If ($bSomething) Then Return MyFunc_Return(0) ElseIf ($bSomethingElse) Then Return MyFunc_Return(1) Else Return MyFunc_Return(2) EndIf EndFunc Func MyFunc_Return($iReturnCode) Switch ($iReturnCode) Case 0 MsgBox(0, "Code #0", "Something for code 0.") Case 1 MsgBox(0, "Code #1", "Do something else for the code 1?") Case 2 MsgBox(0, "Code #2", "Maybe something for the 'else' here?") EndSwitch Return $iReturnCode EndFunc Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.
Xibalba Posted January 20, 2014 Author Posted January 20, 2014 (edited) AlmarM, yes! I got no need for any return value though, so I can just delete this line: Return $iReturnCode Thx Edited January 20, 2014 by Xibalba AlmarM 1
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