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):

But i get this error "Attempt to call function 'time_left' in base 'null instance' on a null instance.".
Can someone help me?

asked Dec 6, 2019 in Engine by Hashtop (36 points)

1 Answer

+1 vote
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.

answered Dec 6, 2019 by kidscancode (17,714 points)
selected Dec 6, 2019 by Hashtop
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 How to use this Q&A? before posting your first questions.