Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Spot the infinite loop =-(


zidsal
 Share

Recommended Posts

Well I'm making some bosses (with my new ultra urber cool SS subs and functions) But this is really getting to me and I can't figure out whats wrong:

Whats suppose to happen:
you lose health every milisecond for 5 ticks. After 5 ticks you take additonal damage:
What really happens the ticks go on for ever.

```
Sub Decay(victim)
dim Count
Count = 0
        If Count < 5 then
                Call SpellAnim(6, getplayermap(victim), getplayerx(victim), getplayery(victim))
                Call BattleMsg(victim, "Your body begins to decay..", GREY, 0) 
                Call SetPlayerHP(victim, getplayerhp(victim) - 1)
                Call SendHP(victim)
                Count = Count + 1
            End If

            If Count  = 5 then
                Call RemoveTimer("Decay " & victim)
                Call playermsg(victim, "Your body has decayed",4)
                Call SetPlayerHP(victim, getplayerhp(victim) - 5)
                Call SendHP(victim)
            End If
    End Sub
```
so anyone want to take a crack at this?
Link to comment
Share on other sites

Count is always 0 and 1, it will never reach 5\. So it will never turn the timer off. Im guessing Decay(Index) is called via the timer, you need to make Count a global value and only set count as 0 when the timer is activated.

If it keeps running count = 0 everytime the counter ticks, guess what? it resets it and your 5 steps away from 5, again :P
Link to comment
Share on other sites

Feeling generous :)

Dont forget to resetdecay when they are first infected!

```
'.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.
Sub ResetDecay(Victim)
'.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.
Dim Count

Count = 0
Call PutVar("Decay.ini", Cstr(Victim), "Count", Cstr(Count))

End sub

'.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.
Sub Decay(victim)
'.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.:!:.
dim Count
Count = Int(getVar("Decay.ini", Cstr(Victim), "Count"))

if Len(Cstr(Count)) = 0 then
Count = 0
End if

If Count  => 5 then
Call RemoveTimer("Decay " & victim)
Call playermsg(victim, "Your body has decayed",4)
Call SetPlayerHP(victim, getplayerhp(victim) - 5)
Call SendHP(victim)
Else
Call SpellAnim(6, getplayermap(victim), getplayerx(victim), getplayery(victim))
Call BattleMsg(victim, "Your body begins to decay..", GREY, 0) 
Call SetPlayerHP(victim, getplayerhp(victim) - 1)
Call SendHP(victim)
Count = Count + 1
Call PutVar("Decay.ini", Cstr(Victim), "Count", Cstr(Count))
End If

End Sub
```
Link to comment
Share on other sites

you can also static the counter. just replace dim with static. I think you can do that with sadscript. basically a static is a variable that does not reset when the sub is called. u would have to take out "Count = 0".
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...