From 7a2f860519e1a79dccc1bf7fbad619bf7dbad74e Mon Sep 17 00:00:00 2001 From: theskywinds Date: Sun, 18 May 2025 15:40:05 +0200 Subject: [PATCH] Attempts at fixing signals --- collectables/crystal/collect_crystal.gd | 6 ++++-- player/smallPlayer/playerScript.gd | 11 ++++++----- project.godot | 4 ++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/collectables/crystal/collect_crystal.gd b/collectables/crystal/collect_crystal.gd index 4c5ac68..12c3588 100644 --- a/collectables/crystal/collect_crystal.gd +++ b/collectables/crystal/collect_crystal.gd @@ -1,12 +1,14 @@ extends Area2D -signal Pickup +signal _picked_up func _ready(): + add_to_group("crystals") print("ready") func _on_body_entered(body: Node2D) -> void: - emit_signal("Pickup") + add_user_signal("_picked_up") + emit_signal("_picked_up") self.queue_free() print("meow") diff --git a/player/smallPlayer/playerScript.gd b/player/smallPlayer/playerScript.gd index 5fe164e..585aab2 100644 --- a/player/smallPlayer/playerScript.gd +++ b/player/smallPlayer/playerScript.gd @@ -1,12 +1,13 @@ extends CharacterBody2D const SPEED = 3.0 -#func _ready() -> void: -# var collectable = get_node("collectableCrystal") -# collectable.connect("pickup",self,"collect") +func _ready() -> void: + var crystals = get_tree().get_nodes_in_group("crystals") + for crystal in crystals: + crystal.connect("_picked_up", Callable(self, "collect")) -#func collect(): -# print("something") +func collect(): + print("something") func _physics_process(delta: float) -> void: # Get the input direction and handle the movement/deceleration. diff --git a/project.godot b/project.godot index 3f03029..8234b76 100644 --- a/project.godot +++ b/project.godot @@ -14,6 +14,10 @@ config/name="The crystaline adventure" run/main_scene="uid://bj1x4w8ek53u1" config/features=PackedStringArray("4.4", "Forward Plus") +[global_group] + +crystals="" + [input] moveLeft={