How to assign a label text property to a timer's time_left function?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hashtop

I’m trying to assign the text property of the label node to the time_left function of a timer called “TestTimer”. Here is the code:

func _process(delta):
self.set_text($Timer.time_left())

But i get this error “Attempt to call function ‘time_left’ in base ‘null instance’ on a null instance.”.
Can someone help me?

:bust_in_silhouette: Reply From: kidscancode

If your Timer’s name is “TestTimer”, then you need to reference it with $TestTimer. Also, even if you fix that, you’ll get an error because the text property of the Label node takes a string, and you’re trying to assign a float. Finally, time_left is a property of the Timer node, not a function.

The correct code would be:

func _process(delta):
    text = str($TestTimer.time_left)

Note: This only works if “TestTimer” is a child of the node this script is on. If it’s in another location, you’ll need to provide the correct path to the node.