Not Detecting Connection? (Print Statement Shows Otherwise)

I'm not sure what's going in, in this case. I added a print statement to _on_GodotArea2D_area_centered() to see if the collision was being made, and it was. Each time I enter the area with Godot, it says "a contact was made." But for the life of me I can't understand why the counter isn't being updated.

Oddly, using a print statement also reports the same amount of gems, as well.

A bit of guidance here would be appreciated.

var counter := 0

onready var godot_area: Area2D = $Godot/Area2D
onready var ui_counter: Label = $UI/Counter

func _ready() -> void:

func _on_GodotArea2D_area_entered(_area: Area2D) -> void:
    counter += 1
    print("There are "+ str(counter) + " gems.")
    ui_counter.text = "Gems: " + str(counter)

  • Răzvan Cosmin Rădulescu(razcore-rad) replied

    Yes, so it's true that you did connect godot_area to the _on_GodotArea2D_area_entered() function in the sense that you specify them in the connect() function.

    You can always check the *Tests.gd files as a guide if you get really stuck, it might give you an idea of what to fix. Although I would say do that as a last resort because the scrips are generally advanced and sometimes might bring in more confusion if you don't know what to look for.

    In your case, like I mentioned, you indeed connect the right nodes, but we can connect them in two ways:

    1. connect("signal", object, "function"): this means we connect the current node because all the function calls can be thought of like this: self.connect(). So to be clear we connect the self node's "signal" to "function" in object. That's how we think about this function call.
    2. object1.connect("signal", object2, "function"): more generally, we can connect object1 node's "signal" to "function" in object2. Where object2 can also be self or any other node we have access to.

    You use connect("area_entered", godot_area, "_on_GodotArea2D_area_entered") which can be thought of like item 1. in the list: connect self node's "area_entered" signal to function "_on_GodotArea2D_area_entered" in godot_area.

    You're trying to connect the "area_entered" signal from self, which is a YSort node. And we know for sure that YSort nodes don't have an "area_entered" signals because that's an Area2D specific signal.

    So think about the multiple ways we can connect nodes signals and hopefully you can figure it out!

    Let us know how it goes.