Even while following tutorials, I like to make (mostly stylistic) changes on how I’d code something in real life. The logic is the same after all.
I initially had this to set the game over score:
extends Control
@onready var score = $Panel/Score
func set_score(new_score: int):
score.text = "Score: " + str(new_score)
func _on_retry_button_pressed():
get_tree().reload_current_scene()
But it gives me a null exception, the score
variable is always null:
The tutorial’s code works fine:
extends Control
func set_score(new_score: int):
$Panel/Score.text = "Score: " + str(new_score)
func _on_retry_button_pressed():
get_tree().reload_current_scene()
So why is my onready variable always null? Is _ready not called for script instantiated variables?