- Home /
Making an integer minimum value 0
Hello, i'm new to programming and I'm stuck at this: I'm creating a health system and it's all good so far, but I need the health to stop at "0", but instead it goes down and down to negative numbers. How can I solve this? Thanks in advance.
Comment
This is also a great place to address what happens when health goes below zero.
health = health - damage;
if (health <= 0)
{
health = 0;
DieLikeAHero();
}
Answer by lll4louis · Aug 31, 2018 at 07:30 AM
if (health <= -1)
{
health = 0;
}
Why <=
? That makes not much sense. If it is already 0 you don't have to set it to 0 again. It's just a waste of instructions. The accepted answer (which btw is 5+ years old) has it right So this answer is unnecessary and misleading.