![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | axierratic |
hello! i’m new to Godot (and programming in general) so i apologize if this is a simple thing, but i haven’t been able to find a clear answer on how to store a player-entered name so it can be used in dialogue or events throughout different scenes within the project.
i have a singleton in my project settings, and a scene with a ControlNode/Panel/VBox to contain a Line Edit and Button. the Line Edit sends a signal to my singleton.gd (attached to scene ControlNode):
var player_name
func _on_LineEdit_text_entered(new_text):
player_name = new_text
print(player_name)
the above does actually print whatever gets entered in the Line Edit, so it’s recognizing the text input. however, the Button to accept the entered name and move onto the first scene has this script attached:
func _on_Button_pressed():
get_tree().change_scene("res://Scenes/TestWorld.tscn")
print("Welcome " + str(singleton.player_name))
which only prints “Welcome Null”. i’ve tried different configurations with ‘get_node’ or ‘get_text’ and they always print Null, or leave it blank, or break from some type of error. i am new to all this, so maybe i’m misunderstanding how singletons work, or referencing the player_name incorrectly, but any help on this would be most appreciated!
tl;dr can a singleton be used to store the text entered into a LineEdit node (such as a player name)? if so, what’s the syntax to store and reference it?