0 votes

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?

in Engine by (39 points)

1 Answer

+2 votes
Best answer

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.

by (21,714 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.