Array properties?

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

How would I get the masses of multiple objects, get_children().mass doesn’t work.

:bust_in_silhouette: Reply From: Zylann

You can get the mass of a particular child by using get_child(index).mass.
Then you can loop over all of them to get their mass one by one, assuming they all have a mass property:

for i in get_child_count():
    var child_mass = get_child(i).mass

If you want them all in an array:

var masses = []
for i in get_child_count():

Thanks! Is there a way for me to access this array from another script, because it treats it as a float when reference it like: get_node(nodepath).get(“masses[index of my choice]”)

a human | 2020-03-30 20:02

What are you trying to achieve actually? You might not need an array specifically, nodes are just there available. I’m not sure which advice to tell you, “from another script” could be so many things…

If all your nodes with a mass are under a different node from the one where you need the masses, either use get_node("path/to/parent/of/masses") and iterate over its children, or expose a function to obtain it and call get_node("path/to/parent/of/masses").get_masses(), I guess

Zylann | 2020-03-30 20:10

Nevermind, sorry for wasting your time. Node.masses[index] works.

a human | 2020-03-30 20:13