Creating an array using a group's node's variables

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

Hello, I’m new to this, so sorry if I’m wrong at something

I have created a checkpoint and coins in a platformer game, the checkpoint change the spawnpoint’s(an autoload) position to the checkpoint’s, it all working fine, the problem is the coins. The coins resets whenever the player died even if it collected before the checkpoint is activated.

I planning to make a variable iscollected for the coins, if is true then the coin visible is false, not queue free. The coin is in group “coins”. I made an array variable in the spawnpoint. In the script I use get group node name (“coins”). My plan is to assign the array into the variables from the group so that I can checked if its true or not when the player died, if its true, then it will queue free, the problem is I don’t know how to do that.

If I did array = get group node name (“coins”)
then the array have all the name of the nodes, not the variable of the nodes.

If I make a check function return if the variable is true for the coins and did this instead:
for member in get group node name(“coins”):
array = member.check()
the array has only one variable stored, changing in fact.

I just need to assign the array variable to the all node’s bool variables with get group or other method. I am sorry that I do not add the code pic or that I didn’t explain enough to be understandable.

:bust_in_silhouette: Reply From: Inces

get_nodes_in_group(“coins”) will be an array containing references to the nodes. So You can :

for member in get_nodes_in_group("coins") :
      if member.iscollected == true:
           member.visible = false

Thank you for the answer :smiley:

scopericrit | 2022-04-12 22:37

Nope, didnt work, when the player died, the scene resets. AFTER the get_node_in_group, the coin with is_collected is true is gone, but the scene resets, so the coins resets, if I make the tilemap an autoload, the coins gone even if no checkpoint is activated. I forgot to tell you that the coins is added by tilemap.

scopericrit | 2022-04-13 22:32

Ah, You reset whole scene. This is rarely a good idea. This forces huge amount of data into Autoload scripts. Another problem is that completely new nodes are created as coins when You reset, so get_nodes_in_group contains completely new set of nodes after reset.
It is much more ellegant and easy to manually reset scene - clear tilemap, set nodes to visible, reposition player and so on. If You still don’t want to do it, You need to keep and update information about coins in dictionary in any Autoloaded script, it will overcomplicate whole design. Resetting scene is only good, when You really want to always restart everything.

Inces | 2022-04-14 14:47