Did you use a view with 100 cels?
One small addition, if you ever change the health by more than an increment of 1, then there is a chance you will miss your marks and not display the messages. Likewise, you may actually jump past the 100 mark and not die.
What I would suggest is actually using flag as an integer instead of a boolean. Then you can use < than instead of an = sign to check for print messages against the flag variable to see if the print statement needs to display or not. Also, may as well stick in a variable to see if the health should be dropping or not, as well as a default value for the health.
(local
flag = 0
counter = 0 // used to count, if carried from room to room place in main.sc
counterMax = 15 // how many cycles worth of time equals 1 health bar
health = 100 // if this is carried from room to room, place in main.sc
doHealthDrop = TRUE // likewise, if carried from room to room place in main.sc
)
...
(method(doit)
(var dyingScript) // If you are going to use the death handler, don't forget this
(super:doit)
(lifeMeter:cel(health)) // keeps the health bar updated to correct cel
(if(doHealthDrop) // only do this stuff if we are counting health
// handle the timer here... if this spans rooms place this bit in the main.sc doit method
++counter
(if(counter > counterMax) // counts cycles
--health // subtract 1 from health
= counter 0 // reset cycle counter
)
// when the health falls below certain levels, display messages.
(switch(flag) // finds out just how bad off we are known to be
(case 0 // As far as we know everything is fine...
(if(< health 65)
Print("You don't feel so well.")
= flag 1
)
) //ends case 0
(case 1
(if(< health 30)
Print("You are doubling over in pain.")
= flag 2
)
) //ends case 1
(case 2
(if(< health 5)
Print("Death is imminent.")
= flag 3
)
) //ends case 2
(case 3
(if(< health 1)
Print("You are dead.")
= flag 4 // just to get us out of this switch
// Rather than this, you could always call the death handler instead
// = dyingScript ScriptID(DYING_SCRIPT)
// (send dyingScript: caller(3)register("You're dead"))
// (send gGame:setScript(dyingScript))
)
) //ends case 3
)//ends flag switch
)//ends if doHealthDrop TRUE
)// ends doit method
My implementation is slightly different, I count down from 100. I also stuck everything in the doit method instead of making use of the changestate method too. One reason that I added in the doHealthDrop variable, is that during cutscenes or animations, those could go awry with the doit method dropping the health. It would be better off to stop the timer by setting the doheathDrop variable to FALSE when any cutscene animations start and then simpy setting it back to TRUE as the animation ends. All in all though the same basic idea is the same, just the implementation is slightly different. One thing that I wouldn't do however is actually use a view with 100 cels. Instead I would probably use one with 10 or 20 cels and then probably divide the health by however many cels I made.
= healthBarCel (/ health 20) // where healthBarCel is another local or global variable depending on scope
(lifeMeter:cel(healthBarCel)) // instead of what I have in the doit method now.
You should also be able to see yet another variation in the source code of aquarius. There I also took into account whether or not the ego was actually moving. While standing still health is regained, while moving health is lost.