for i in $sirali.get_children()

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

onready var main = get_tree().current_scene
func sirali_ates():
for i in sirali.get_children():
var c = $carklar.instance()
main.add_child(c)
c.transform = i.global_transform
pass
“c” Total 5 scene instance()

Here I instance the scenes named “carklar”.
So how do I access these uploaded scenes?
So I installed 5 of the “Carklar”.
How to access 1. “c” or 2.“c”
(“Carklar” = “bullet” I have to shoot one by one)
İ try . print (c[0]) . not work

:bust_in_silhouette: Reply From: DaddyMonster

You’re adding them to a variable which is being replaced with each loop. Add them to an array to keep them handy.

Hold on, what’s going on with var c = $carklar.instance()?? That either crashes (tells you there’s no such method) or you’ve written an instance() method in that script. Seems very odd, can’t imagine how that could work so I’ve changed it below to a standard set up but if you have a reason for it being this way then let me know.

onready var main = get_tree().current_scene
var carklar_scene = preload("drag_path_to_scene_into_here")
var carklars = []

func siraliates():
    for i in sirali.get_children():
        carklars.append(carklar_scene.instance())
        main.add_child(carklars[-1])
        carklars[-1].global_transform = i.global_transform
    for c in carklars:
        printt("my new bullet nodes:", c.name)

umarım yardımcı olur!

I misspelled $Çarklar here.
worked great
Thank you very much for taking the time to solve my problem.
########
I don’t understand this [ -1]. I’ve encountered a lot but I don’t know what it does

ramazan | 2022-01-15 08:07

Glad it worked for you.

Say we have:

var my_array = ["a", "b", "c"]

my_array[-1] addresses the last item in the array. In the above case it returns “c”.

If you put it after my_array.append("d") then my_array[-1] outputs “d” because append adds it to the end. It’s an easy way of addressing what you just put in the array.

DaddyMonster | 2022-01-15 09:45

you’re super . Thank you very much again

ramazan | 2022-01-15 11:12