HaikuBotStalksMe t1_itseyy7 wrote
Reply to comment by relefos in [WP] You are an NPC in an RPG. Normally, your attack is set to 1. However, a player used a cursed item on you, reducing your attack by 2, causing it to underflow, making you the most powerful in the game. by alegonz
That's a fair point. But like usually overflow or underflows in games happen because you didn't bother setting up a safe upper or lower bound.
Like in 8 bits, you're gonna get up to 255. As such, I wouldn't let someone have more than like 200 points, and no single action will allow them to gain more than 50 points. And each time they gain or lose, I'm gonna make sure that if the value will be negative, then they can only go to 0 ("if score < pointslost: score = 0; else score -= pointslost"), and if adding any score goes over 200, then the score is set to 200.
My coworkers complain I overthink/over-safety my code sometimes, but hey, why risk it?
relefos t1_itvqq8n wrote
I 100% agree, just clarifying that under flow has nothing to do with setting a lower bound on an int
Going lower than your lowest bound is still just overflow
Underflow is specifically when you try to represent a floating point number smaller than your float can possibly represent. ie 0.0000000001 instead of 0.00001
Just a semantics misunderstanding thing I see a lot bc it honestly is unnecessarily confusing 😂
HaikuBotStalksMe t1_itvtis3 wrote
And you're totally right to point it out! Thanks.
Viewing a single comment thread. View all comments