Writing in multiple labels without overwriting the first one

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Abuameyan

Hi guys! Im trying to do something simple here, I have a global var called “nickname”. Everytime a user puts a nickname in one scene, this scene picks it up with the global var and writes it in a label. The thing is, it always writes the first one, and I didn’t get why. This is the code:

func _ready():
if $Fondomenu/ColorRect/VBoxNicknames/Nickname.text == “”:
$Fondomenu/ColorRect/VBoxNicknames/Nickname.text = Nickname.nickname

elif $Fondomenu/ColorRect/VBoxNicknames/Nickname2.text == "":
	$Fondomenu/ColorRect/VBoxNicknames/Nickname2.text = Nickname.nickname

It’s not entirely clear how the above script is intended to interact with your global nickname variable. However, the code you show above is in the _ready() function, so it’ll only ever execute once, when the node it’s attached to is added to the scene tree.

I’d assume that’s the underlying cause of the issue…

jgodfrey | 2023-05-19 00:29