I have a bug I reproduced it
heres a picture
heres the code
extends Control
var score = 0 @onready var label: Label = $Label
#or get node they both dont work
Called when the node enters the scene tree for the first time.
func _ready() → void:
print(get_children())
pass # Replace with function body.
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(delta: float) → void:
label.text = ‘11’
heres the error:
Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘null instance’.
its not a code error but something in the editor
Hello again, @sigmamaul9! I finally understand why you have error. You write a change of text property for label at _process function. At first frame the label is null (_ready still not called). Try to update the label by signals for more clear code.
I updated this part
func _process(delta: float) → void:
label = $Label
label.text = ‘11’
still gives same error
the script can find child node using get_children() function but cant directly get it
do you any settings or things in the inspector that can affect this.
You at each frame assign a $Label node to label variable.
To get the solution you don’t need to use _process function for change label.
Try this way:
extends Control
var score: int = 0
@onready var score_label: Label = $Label
signal score_count_changed
# Connect this function with score_count_changed signal
func on_score_count_changed():
score_label.text = "Score: " + str(score)
# Call this when player reach the score
func add_score():
score += 1
score_count_changed.emit()
# For example
func _ready():
# Call add_score function when Node is ready
add_score()