how do you deal with “%” in your games/projects?
If you put % on your numbers ( like 100% damage) it is no longer an int or float and you can not work with it. But you might still want to tell the user/player that is an % bonus or effect.
Is there a smart way to deal with this or do I have to drag the % around or add remove it all the time depending on the circumstances.
Is there a fast easy way to ad % in or remove it from my numbers?
I can deal with this for sure but some hints or best practices from veterans would go a long way.
I can calculate/work with %. The problem is in the % symbol and how you deal with it. Have it in your variable or ad it only when you want to tell the player about it? How to do this in a smart way.
Of course, I usually prefer to keep these things numerically between 0 and 1, for example, I put the user’s health at 1 and the demij at 0.2 and multiply it by 100 when displaying, This keeps the calculations in sync, and it will usually be very easy to tell if it is a percentage in the code.
So you add the % only when showing the player, I thought about that too but not all my modifiers are % which makes it more complex to use as a general solution. At that point I need some extra information to make the decision % or not % in the code and that feels a bit clunky.
…hmmmmm…
One is a % the other a flat bonus. If I want to make a general solution how to deal with this (in your way) I need an extra bit of information that tells the code that the modifier is a % and does the thing.
unless…
Just thinking…
if I keep all % under 1 (like you) and tell the code only do the % extra if the number is lower than 1… than that would work. Fringe case is of course a flat bonus of 1 and 100% bonus or more.
It’s an interesting idea, I recently developed a plugin called Elementum EC that allows the management of specific data classes, it’s still in the testing stages, but if we move all the percentage values to a new class everything will be great, but let’s look for a faster solution…
If you mark all values between 0 and 1 as a percentage, the calculations do not need to be changed, but the display to the user becomes more complicated, the only positive is that their formatting in the code is different from other numbers, it does not seem very optimal…
Right now I debate between adding the % just in the name to inform the player or using a list with all mods that are % to inform the “add %” function.
Both work, both have ups and downs.