Store a refrence to a node inside an array

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

I have a reference to a node:

var player
func _ready():
    player = get_node("/root/World/map/Player")

and an array:

var dialogue_1 = [
	[player],
	"Nice to meet you Somebody",
]

but when I print:

print(dialogue_1[0][0])

it gives me Null, what is the proper way to store a reference to a node inside a list?

:bust_in_silhouette: Reply From: kidscancode

It has nothing to do with storing it in an array. If you try print(player) in _ready() you’ll see it’s null as well.

You can’t call up the tree in _ready() because wherever this node is, “World” is not ready yet. Nodes become ready in reverse tree order - children first, parents last.

I’ve already tested print(player.name) and got player so I’m pretty sure that part works

Kia Azad | 2020-05-12 07:06

:bust_in_silhouette: Reply From: Kia Azad

Found the problem, my dialogue was defined after the _ready() block but outside it, once I’ve moved it inside the problem was solved.