Is Node.list.append_children(players) a method?

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

Hello!

I’m making a local multiplayer 2D platformer (which I’m very proud of, by the way xD), and I recently added a multi-target follow camera from this weirdly amazing tutorial:

But then I wanted to add a system for joining the game manually, and then I realised to do that, I’d have to make an array containing all the current players and then append all of those to the “targets” list in the multi-target camera’s script.

Here’s the code:

	
for _i in $Players.get_children ():
	print (_i)

$MultiTargetCamera2D.targets.append(Players)

…Then the error basically says it’s appended the “Players” node and not the children of it (the actual players).

I don’t really know how to do this, so any help would be great. :slight_smile:

:bust_in_silhouette: Reply From: Redical

Actually, I solved it!

Here was the solution:

for _i in $Players.get_children ():
    Players.append(_i)
    print(Players)
    $MultiTargetCamera2D.targets.append(_i)

So basically, I just manually added it inside of the loop that got each node in the list.
It works perfectly, and right now I’m implementing the player spawning.
:smiley:

you can also do this like this

$MultiTargetCamera2D.targets.append_array(Players.get_children())

more info on append_array

OgGhostJelly | 2023-01-08 09:15