Any non-obvious issues using decimals for HP, etc?

K

Kululu17

Guest
Hi all,

I am setting up some of the basic variables for a game, and am trying to decide if I allow non-integer values for things like player HP, Hunger, etc.

The issue is with things that give bonuses, etc. Let say a weapon has a standard damage of 2, and I want a player skill to give a 10% bonus. If I use integer values, the bonus doesn't work 2.2 rounds to 2, so no bonus. That's just one example, but there are lots of things that I want to apply several bonuses to, which would create non-integer numbers.

I see three approaches:

1. Use really big numbers for everything so even with integers and rounding it will still work out (make the standard damage 20 instead of 2, and standard HP 1000, etc.)

2. Just use decimals, but round off when displaying them.

3. Switch bonus with probabilities - so 2 damage with a 10% bonus would be 2 damage 90% of the time and 4 damage 10% of the time... well you get the idea.

I know Gamemaker numbers are all floating point numbers anyway, but just wondering if there is some reason (other than ease of display) to keep everything as an integer.

Thanks!
 

Hyomoto

Member
As far as I know it doesn't matter. Let's say, for example, you wanted your hunger to go from 0 to 1. Well, you could just make max 1000 and then do a hunger / max_hunger when needed. Or you could use hunger - 0.001. Unless someone has some horribly insightful comment to add, the only thing you are deciding on is scale. What does '1' HP represent? Or, another way of looking at it, what series of numbers makes sense to you while coding? For comparison GM uses some very small number like 0.000000001 so I suppose using decimals you could theoretically have rounding errors but really you are just deciding what is easy for you to understand. You can show the player whatever you want. If you want to track health as a series of letters, you can always display "GOOD HEALTH" to the player. It really doesn't matter very much.

Which I think is what you were asking.
 

NightFrost

Member
For the sake of clarity I tend to make all metered variables integers. When dealing with percentage bonuses, the final adjusted value gets rounded before being applied. The value ranges of course need to be large enough so small adjustments like +5% have a meaningful impact. Naturally everything works just as well with decimal values if you want to go there.
 
K

Kululu17

Guest
Hey guys,

Thanks for the feedback. I didn't think there would be an issue, but sometimes there are things that may not be obvious to a non-programmer like myself. Like the tiny differences when doing floating point math that can lead to different results between windows and HTML5.
 
Top