Godot Version
Godot Engine v4.2.2.stable.official.15073afe3
Question
I’m making a flappy bird copy and want to update a variable “game_over” to be true when the player collides with an area named “KillZone”.
I’m instantiating killzones during runtime so I have put them in a group called “KillZones”. But I also have to constantly update the nodes in the group “KillZones” for when new ones are spawned in. Doing this gives thousands of errors though so I want to know if it’s possible to do in another way or at least remove the errors, thank you in advance
Here is the error:
E 0:00:00:0859 general_manager.gd:9 @ _physics_process(): Signal 'body_entered' is already connected to given callable 'Node(general_manager.gd)::_on_kill_zone_body_entered' in that object.
<C++ Error> Method/function failed. Returning: ERR_INVALID_PARAMETER
<C++ Source> core/object/object.cpp:1358 @ connect()
<Stack Trace> general_manager.gd:9 @ _physics_process()
And in an autoload I’ve got this code:
extends Node
var score = 0
var game_over = false
# Connecting to game_over signal in all killzones every time a pillar spawns
func _physics_process(delta):
var kill_zone = get_tree().get_nodes_in_group("KillZones")
for KillZone in kill_zone:
KillZone.body_entered.connect(_on_kill_zone_body_entered)
# Changes game_over variable to true
func _on_kill_zone_body_entered(body):
var death_sound = get_node("/root/Game/DeathSound")
if game_over == false:
death_sound.play()
print("Player died")
game_over = true
It is worth noting that the code works perfectly fine, it just gives tons of errors