About Percentages

Hello!

I want to learn something about percentages.
Here’s my question: I’m trying to code some “health regeneration” system. In some decisions, your character will take damage and loose some of his/her health. In percentages, player’s maximum health will be %100. But there is a problem that I couldn’t solve. In regeneration system, if you are not wounded, your health will regenerate in time. I control this regeneration values. Like, in every choice, you will regenerate a portion of your health but, if I add health to player like “*set health +10” it can pass over 100 (I mean, max health is 100; but with this idea, the health can be 200 or bigger). How can I code this maximum health system?
Thanks =))

What i would do is make a maxhealth variable. Then make an if statement, saying
*if maxhealth < health
*set health maxhealth
*else
nothing
You can add these lines after each regeneration to make sure it never exceeds the maximum.
(Here maxhealth is 100)
This will also give the benefit of being able to dynamically change what the maximum health of your character can be, so he can be crippled and have less health, or recieve an upgrade / magical gift and gain more. This will ofcourse have you go away from perentage display, but that is only an idea :slight_smile:

There is also fairmath (halfway down the page):

Using fairmath will prevent health from every reaching 100 though (IIRC) as it doesn’t like anything outside 1 to 99. (Use fairmath to raise, and normal to lower.)

Thank you guys =))