#How do you edit a node's script variables inside a singleton?

9 messages · Page 1 of 1 (latest)

spark falcon
#

Any ideas, on why its printing <null>?

obtuse linden
#

Is your Gateway.gd autoloaded?

What does the code inside Gateway.gd look like, specifically your var1 assignment and what does the script you try to access it look like.

spark falcon
#

I fixed the issue.

Gateway.gd singleton (Autoloaded)
func _ready():
#var node = get_node("../SceneHandler/Login")
#print(node.var1)

The other scene didn't load in fast enough, which caused node.var1 to return <null>

I was following a network video, and I got confused on accessing a variable from get_node()

#

I made a silly mistake, thanks for helping me find it!

obtuse linden
#

Try ctrl dragging a node into your script which will create an onready variable declaration in your script. that wya you avoid that problem

#

Thats generally how you should handle this. the @onready will help you a lot in that regard

spark falcon
#

I think Autoloads have precendence over nodes, who have @onready

On my login.gd
@onready var var1 = "String"

I printed var1 from gateway.gd (Autoloaded singleton) in the _ready() it printed <null>

obtuse linden
#

autoloaded gets loaded first, that's correct

#

you could also emit a signal from your node to let your autoloaded script know thst the node has loaded