In my characyter’s scene I added a canvas layer with a Label inside, but I cannot make it appear.
I have added @export var progression: int = 0 @onready var label: Label = $Label func _on_progression_value_ready() → void: $Label.text = str(progression), but it still does not want to work
Just follow the node names from the node that has the script to the target node and separate them using /. Exactly like specifying file paths in computer’s file system.
If the script is in scene’s top node you can right click on the target node and do “copy node path” and paste it into the script. Or you can just drag the node from the scene tree into the script.
Do not write “@onready var …” lines by hand. Press Ctrl and drag and drop the node from Scene tree to your code. That’s how you always get the correct path.
You are already getting the label node to the label variable on third line.You do not need to get it again in the fuction. Use the label variable instead:
E 0:00:01:303 _on_progression_value_ready: Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘Nil’.
char_controller.gd:74 @ _on_progression_value_ready()
char_controller.gd:74 @ _on_progression_value_ready()
I don’t know for sure why using label variable doesn’t work. My guess is that the function _on_progression_value_ready is called before @onreadyvariables are set. You could add _ready function and check which function is called first.
If “_on_progression_value_ready” is printed first, label variable is still null in the _on_progression_value_ready function. How to fix this, I don’t know without seeing more code.
The function certainly gets called because the error message says the errors happened inside that function. But label’s ready will happen before character body’s ready. And label is initialized in character body’s @onready.
Either put label.text = str(progression) inside character body’s _ready() or use the literal path in _on_progression_value_ready() like you did before. The former is the better solution.