Jump to content

Select/Case within a function


Smorg
 Share

Recommended Posts

Look at this function...

Func GetLife($Direction, ByRef $Timer )
    Select
        Case $Direction = "up"
            For $Search = $HealthPixel - $Top To 0 Step - 1
                $HealthColor = PixelGetColor($HealthX, $Search + $Top)
                If ($HealthColor <> $HealthRef[$Search]) And ($HealthColor <> $PsnRef[$Search]) Or $Search = 0 Then
                    $LifePercent = Round(100 * (($Bottom - ($Search + $Top)) / ($Bottom - $Top)))
                    If $Search = 0 Then
                        Return $Top
                    Else
                        Return $Search + $Top + 1
                    EndIf
                    ExitLoop
                EndIf
            Next
        Case $Direction = "down"
            For $Search = $HealthPixel - $Top To $Bottom - $Top
                $HealthColor = PixelGetColor($HealthX, $Search + $Top)
                If ($HealthColor = $HealthRef[$Search]) Or ($HealthColor = $PsnRef[$Search]) Or $Search = $Bottom Then
                    $LifePercent = Round(100 * (($Bottom - ($Search + $Top)) / ($Bottom - $Top)))
                    If $Search = $Bottom - $Top Then
                        Return $Bottom
                    Else
                        Return $Search + $Top
                    EndIf
                    ExitLoop
                EndIf
            Next
    EndSelect
    msgbox(0, "blubby", "blub")
    Exit
    If $Timer = 1 Then
        If TimerDiff($Sleep) > $DrinkDelay Then $Timer = 0
    EndIf
    If $Timer = 0 Then
        If ($LifePercent < $LifeRpotDrinkPercent) And ($LifePercent > $LifeFpotDrinkPercent) Then
            msgbox(0, "blubby", "blub")       ;debug
            Exit                                          ;debug
            Drink(1)
            $Timer = 1
            $Sleep = TimerInit()
        ElseIf $LifePercent < $LifeFpotDrinkPercent Then
            Drink(0)
            $Timer = 1
            $Sleep = TimerInit()
        EndIf
    EndIf
    If $LifePercent < $ChickenPercent Then Chicken()
EndFunc   ;==>GetLife

Notice where i put the debugging message box... nothing below that ever gets executed. I execute the function, but after the EndSelect, it exits the function. Why?!?

it should show the message box, then close the script. Instead it continues as normal without showing the box.

Edited by Smorg
Link to comment
Share on other sites

hm, maybe it has to do with my timer... still trying to figure it out. EndSelect doens't end the function though right?

aah you are probably right. Return exits a function? I'll try byref instead of return.

It returns a var called $HealthRef. I wanted to try to do this so that i can make that not a global var. I wish there was a way to do this without globals.

Edited by Smorg
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

  • Recently Browsing   0 members

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