Rounding up/down of numbers in variables

Hi all, me again :slight_smile:

What it is i have a global variable for my tanks health but i have a variable driven enemy attack, how i have done it is in the file attached, but if you notice when you get attacked the health text in the health bar comes out because of all the decimal places, is their any way to round the number up or down depending on if its over 0.5 or not :confused:
Tank Commander.rar (1.08 MB)

1 Like

try:

round(Value) or int(Value)  to round
trunc(Value)  to delete the decimals
floor(Value) and ceil(Value) to round down and up respectively

:slight_smile:

2 Likes

What would be the most efficient way, Do i put the rounding up of the number before it gets added to the variable or do i round the vaiable

1 Like

Unless you save a lot of variables per frame (100, 1000?) you will not notice any performance drop. If you are computing such number of variables, use the round function in the same expression line you save the variable, other way do it so you can understand your code when you read it again other day :wink:

1 Like

Thankyou lizard i have got it working as it should, i am making it so if their is a change to a variable the game will automatically save e.g. Variable Level canges from 1 to 2 game will save, obviously i will have it save the game after number has been rounded. :sunglasses:

1 Like

Good job! And good luck with your game! :slight_smile:

2 Likes