How to get the path from a nested node at runtime?

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

I’m trying to access a node nested inside an instance scene created at runtime.

I got at the point where I can manually write the path to the node like this.

for item in slot.get_children():
		if item.is_in_group("ItemsG"):
			get_node(str(item.get_path())+"/Fruit/Amount").set_text(str(Global.inv[1][findSlot]))

Is there a better way to write or doing this in general? Do I keep doing as I’m doing adding strings together this way?

:bust_in_silhouette: Reply From: Eric Ellingson

For each node that is a member of the ItemsG group, if they do not already have a script attached, attach a script and define a member variable that references the label node

# ItemsG.gd

onready var amount_label  = $Fruit/Amount

Then,

for item in slot.get_children():
    if item.is_in_group("ItemsG"):
        item.amount_label.set_text(str(Global.inv[1][findSlot]))