So uhmmm i actually tried like 10+ hours now and i cant find any erros or clues how to fix this. I wanted to change a Label with some data of a dictionary which is perfectly loaded, until line 18. In my Output it easily prints the .name but it wont change the name_label.text ? Any suggestions ?
extends Control
var girl_id: int
@onready var name_label = get_node("/root/GirlProfile/NameLabel")
@onready var relationship_status_label = $RelationshipStatusLabel
@onready var relationship_progress_bar = $RelationshipProgressBar
@onready var info_label = $InfoLabel
func set_girl_id(girl_id: int):
print("Girl ID set to: ", girl_id)
func update_profile(girl_id: int):
var girl_data = Global.get_girl_data(girl_id)
print("Girl data", girl_data)
print("Updating profile for girl ID:", girl_id)
print(girl_data.name)
if name_label == null:
print("name_label is null")
else:
name_label.text = girl_data.name
print("Name label updated:", name_label.text)
if relationship_status_label == null:
print("relationship_status_label is null")
else:
relationship_status_label.text = Global.relationship_levels[girl_data["relationship_status"]]
print("Relationship status label updated:", relationship_status_label.text)
if relationship_progress_bar == null:
print("relationship_progress_bar is null")
else:
relationship_progress_bar.max_value = Global.get_next_level_threshold()
relationship_progress_bar.value = girl_data["relationship_points"]
print("Relationship progress bar updated")
if info_label == null:
print("info_label is null")
else:
info_label.text = girl_data["info"]
print("Info label updated:", info_label.text)
Debugg Output:
Girl ID set to: 1
Girl data{ “name”: “Maya”, “relationship_status”: 0, “relationship_points”: 0, “info”: “Info über Mädchen 1” }
Updating profile for girl ID:1
Maya
name_label is null
relationship_status_label is null
relationship_progress_bar is null
info_label is null
Menu Check
Hi, where is the name label relative to the script the node is on? Is it a child of the current node? If so, then you don’t need to use the root path.
Hi, when you use the change_scene_to_file function, you are NOT using the instance stored in the profile_scene variable. It becomes an orphan node. Also, since you never add the profile_scene instance to the tree, the @onready variables are never initialized because that only happens after the node is added to the tree.
There is not need to instantiate the girl profile scene if you are using the scenetree change scene function. Instead, you can use autoloads to pass information between scenes. Or you can not use the scenetree change scene function and instead add the profile scene to the tree yourself. Make sure to only call the update profile function after it is added to the scenetree, though.