Sign in to follow this  
Followers 0
Smorg

Select/Case within a function

7 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

hmm... that message box comes up for me..

It could be possible because of those "returns" that you have in it, beause if those if statements are true, it returns from the function.

:lmao:

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

EndSelect
msgbox(0, "blubby", "blub")
Exit

exit means exit.

Edited by jinxter

> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

Yes, thats just there so it doesn't continue for debugging. (it would have to reactivate the window i'm working with)

Share this post


Link to post
Share on other sites

aha... sowwy :lmao:

the problem is that it doesn't show the dialog box, or ?

how do you call the function ?


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

haha thanks guys i'm an idiot... return doesn't just return something, it leaves the func at the same time.

Edited by Smorg

Share this post


Link to post
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
Sign in to follow this  
Followers 0