0 votes

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.

Godot version 3.4
in Engine by (15 points)

1 Answer

0 votes

getnodesin_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
by (5,557 points)

Thank you for the answer :D

Nope, didnt work, when the player died, the scene resets. AFTER the getnodeingroup, the coin with iscollected 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.

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 getnodesin_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.

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.