0 votes

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?

in Engine by (235 points)
edited by

1 Answer

+2 votes
Best answer

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]))
by (1,581 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories