You are viewing a single thread.
View all comments View context
58 points

Should it be

PlayerHealth <= 0

?

Otherwise the player could have 0 health and not die? I’m sleep deprived so forgive me if I’m wrong

permalink
report
parent
reply
27 points

Open up ticket first, please. Thanks Codemonkey.

permalink
report
parent
reply
27 points

You are correct.

permalink
report
parent
reply
54 points

Counting this meme as my first FOSS contribution

permalink
report
parent
reply
12 points

Holy shit I was there with you sir! With the zeros and stuff

permalink
report
parent
reply
12 points
*

You are correct about it allowing you to have zero health and not die, but whether or not that’s the correct behavior will depend on the game. Off the top of my head I know that Street Fighter, some versions at least, let you cling to life at zero.

permalink
report
parent
reply
5 points
*

I know this is /c/Progammerhumor, but I wanted to pull on this thread a little bit for my own edification. I’m a Python guy and have been a while, but I’ve dabbled in other languages. The screenshot says “MonoBehaviour” which makes me assume this is mono or a .Net-like language (you know what happens when you assume).

If your player health is a float, would mono or .Net have an issue comparing the float with integer zero “0”? I mean, it seems like floating point precision may make it impossible for it to ever “equal” integer zero, but it also seems like the code isn’t accounting for that precision error.

Am I overthinking this?

permalink
report
parent
reply
7 points

Floating point errors are a product of how floating points work as a mathematical concept. So they’re independent of the programming language and can happen everywhere.

In this case though, I doubt it’s a critical issue. So the player “died” when they actually had 0.000000000027 hp left or whatever. Who cares? Do you need to be that precise?

permalink
report
parent
reply
14 points

Hanging on with 1.70E-31 health.

permalink
report
parent
reply
1 point

As a noob in unity and programming, my understanding is that MonoBehavior only means that this script has to be attached as a component to a game object to function. And has no other meaning - but correct me if I’m wrong please.

permalink
report
parent
reply
-4 points

This won’t work if you can ever take more than 1 damage. If you were at 1 and received 2 damage you would become invincible. You’d want to do less than or equal to.

permalink
report
parent
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 3.7K

    Monthly active users

  • 1.5K

    Posts

  • 35K

    Comments