AutoModerator t1_itpnwjn wrote
Welcome to the Prompt! All top-level comments must be a story or poem. Reply here for other comments.
Reminders:
>* Stories at least 100 words. Poems, 30 but include "[Poem]" >* Responses don't have to fulfill every detail >* See Reality Fiction and Simple Prompts for stricter titles >* Be civil in any feedback and follow the rules
🆕 New Here? ✏ Writing Help? 📢 News 💬 Discord
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
HaikuBotStalksMe t1_itqy3ug wrote
This kind of stuff is why I program safety measures in my game. Like "if x == 0, do blah. If x == 2, do blah2, if x==3 do blah 3. If x > 3, x= 3 continue, if x < 0, x = 0, continue"
relefos t1_itrpu1x wrote
I just wanted to leave a fun fact ~ this is not underflow, it's actually still just overflow. Underflow is when a number is too small to be properly stored as a float
Overflow happens when a number flows out of a certain range, so if you can store a number from 0 up to 255, and you try to add 1 to 255, you overflow. The same is true if you subtract 1 from 0 ~ it's still overflow
Here's this resource: https://www.educative.io/answers/what-are-overflow-and-underflow
u/alegonz if you're curious!
HaikuBotStalksMe t1_itseyy7 wrote
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.
brimston3- t1_itrypm8 wrote
If -1 would overflow then the type is unsigned and the if x < 0
check is too late; unsigned < 0 is never true. You must check the magnitude of the subtrahend against the minuend before the operation.
brimston3- t1_itryrzc wrote
I call this the Gandhi Nuclear option.
Aetheldrake t1_itsav6i wrote
Lol I came here to mention that too
Tho another option would be "all attempts to deal damage somehow heal your victims now"
GANDHI-BOT t1_itryt5g wrote
Go stand in the corner & think about what you have done. Just so you know, the correct spelling is Gandhi.
TypicalPunUser t1_its419s wrote
Ok Gahndi
Classic_Huckleberry2 t1_itt7wlx wrote
"Mornin! Nice day for fishin', ain't it? Hu hua!"
iwrite4myself t1_ittjw67 wrote
I must be missing something. Can someone please explain this prompt like I’m five?
1-2= -1
Would this not simply heal the opponent by one point? How is that the most powerful in the game?
Unless this is some kind of hardcore game where no one can ever heal and players now have a slow-but-reliable healer?
Traps-big-gay t1_ittpg2e wrote
If your code uses unsigned integers it can't handle negatives, so it loops back to the highest positive value
iwrite4myself t1_itu0ejw wrote
Ah. Thank you!
JudgeHodorMD t1_ittymwf wrote
This is about data types in programming. The code only has so many digits to work with. So there’s only so many possible numbers.
Like 0 to 9999, except it’s more like a binary equivalent. No numbers exist that are outside of that range. If you try to go past the limit you can get an error where it basically just loops around.
Viewing a single comment thread. View all comments