Hi How do I get rid of the decimals displayed with this (in 2d if that matters): $Label.text = str($Label/Timer.time_left)
(it displays a count down timer - but with 7 decimals) Thank you.
Hi How do I get rid of the decimals displayed with this (in 2d if that matters): $Label.text = str($Label/Timer.time_left)
(it displays a count down timer - but with 7 decimals) Thank you.
You can use the function, round. Make your variable time_left use the round function.
From Godot documentation
_Rounds s to the nearest whole number, with halfway cases rounded away from zero.
a = round(2.49) # a is 2.0 a = round(2.5) # a is 3.0 a = round(2.51) # a is 3.0_
Hi Sir, thanks for the reply - I'm still however not getting it to work. 'time_left' is a function(?) of the Timer-node, so I'm not sure how your answer should be done in code. What should be changed here?: $Label.text = str($Label/Timer.time_left)
I see, time_left is a inbuilt function used to call the Timer.
I played around with the Timer and this is probably easiest for your purpose. Just convert it to an integer and then back to a string.
func _process(delta):
var time = str($Timer.time_left)
var roundtime = int(time)
$Label.text = str(roundtime)
You can use the round function too, with a slightly more complicated method if you really need to. But this should suffice.
$Label.text = str(round($Label/Timer.time_left))
Thanks Sir_Connery and Dave - Dave, that's a very elegant solution, thanks again.