# not sure why this isnt working

hey all can you tell me what is wrong with the last set of logic bricks here? http://www.antihc3.dyndns.org/fudge/deadhelp.png

the property doesnt turn true when health = 0

Fudge

can u post the .blend? take a little look at that.

Change the value in the property sensor from 0.00 to 0.000000.

With float properties the number of zeros matters.

actually, that isn’t right

you shouldn’t do equality tests on floating points because for example, they aren’t accuate exactly
1.0 isn’t the same as 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1
the result is slightly less

so, you should test for health less than zero, or within an interval

or, you could just use an int property for the health, but you would still want to test if it is negative [because you may subtract 1 some times, 10 others, so what if your killer blow does 10 damage, but it was at 3 already? clearly it will not equal zero]

z3r0 d, did you actually test it before you posted that?

First, setting the value in the property sensor to 0.000000 in the example above does work.

Second, if you had a float property starting at zero, and add 0.1 to it ten times with a property actuator, it would be exactly 1.000000. (I’ve tested this too.)

Rulez:

1. z3r0 d knows all
2. never question z3r0 d
3. z3r0 d rules
hi z3r0 d, how you ?

Rulez: (ammended)

1. z3r0 d knows lots
2. don’t question z3r0 d often
3. blender rules!

Rulez:

1. z3r0 d knows all
2. never question z3r0 d
3. z3r0 d rules

Lol, z3r0_d looks like you have your very own fan club. I think wiseman303 might be right here. Very logical in this case, although I didn’t test it personally. :o Then again, the Blender game engine does do some weird things sometimes.

To just fix the problem and any future problems. Cut to the source. Why in the world would anyone want health as a float? (Not to offend anyone here) Even when the guy gets hit with an axe you use -10. That’s an int. Most games you will hardly see a guy with say “You just took -10.5 damage” or “your health is 5.8”. If there is I’m totally embarassed here. So for health just use an int.

Jason Lin

actually, it wouldn’t surprize me if the output is rounded

``````a = 0.0
for i in range(10):
a += 0.1

print a
if a == 1.0:
print "a == 1.0"
else:
print "a != 1.0"
``````

now, check the output:

1.0
a != 1.0

doesn’t that seem a bit odd? that the number was printed as 1.0 but it failed an equality comparison with 1.0?

the reason why is that 0.1 cannot be accurately represented in a floating point [in fact, 1/5 cannot… it is a lot like how 1/3 is 0.333333333333333 in base 10], so when you add them up 10 times you get just under 1.0 [same as adding up 0.33333333 three times].

which is why you try to avoid equality tests on floats, pretty much the only time it would be used is to check if you are dividing by zero.

furthermore, floats [in blender and whereever else] don’t distinguish between number of leading zeros or trailing zeros.
so, 0.0 and 0.0000 are the same

[however, floats have interesting things like negative zero. I don’t know if they compare as equal to positive zero though]

I was kind of hoping that was true

Yay! z3r0 d knows all!

But the value stored in the property sensor is not a float, it’s a string. I’m not sure how Blender compares this with a float value, but obviously the number of trailing zeros does matter, since ‘0.0’ doesn’t work, and ‘0.000000’ does. (Just try it.)