Jump to content

return function? - simple question


Go to solution Solved by AlmarM,

Recommended Posts

Posted (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 by Xibalba
Posted (edited)

mikell,

Lots of more code is run inside each If statement. Hence the need to stop the timer just prior to returning.

Edited by Xibalba
  • Solution
Posted

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.

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