Jump to content

return function? - simple question


Xibalba
 Share

Go to solution Solved by AlmarM,

Recommended Posts

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 by Xibalba
Link to comment
Share on other sites

Then I'm afraid there is no miracle solution and you'll have to go this way :ermm:

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 by mikell
Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...