Why signals do not work?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Incognito
    extends Area2D
    var position_draw = Vector2(200, 100)
    var _can_click = false
    func _ready():
        var a = Sprite.new()
        a.name = "test_sprite"
        a.texture = load("res://img/120px-Roundel_of_El_Salvador.svg.png")
        a.position = position_draw
        self.add_child(a, true)
        var coll = CollisionShape2D.new()
        coll.name = "test_collision"
        var circle = CircleShape2D.new()
        circle.radius = 200
        coll.shape = circle
        coll.position = position_draw
        self.add_child_below_node($test_sprite, coll, true)
        #    ┠╴test_sprite
        #    ┖╴test_collision
        self.connect("mouse_entered", self, "_on_Area2D_mouse_entered") 
        self.connect("mouse_exited", self, "_on_Area_2D_mouse_exited") 
    func _on_Area2D_mouse_entered():
            _can_click = true #Not work
    func _on_Area2D_mouse_exited():
            _can_click = false #Not work
    func _click_check():
           if _can_click:
                if Input.is_action_pressed("click"):
                      print('Click') #Not work
    func _process(_delta):
:bust_in_silhouette: Reply From: jgodfrey

The above code works fine for me except that you have a typo in your signal name here:

self.connect("mouse_exited", self, "_on_Area_2D_mouse_exited

That should be _on_Area2D_mouse_exitedto match your function name.

Thank you, you helped me understand the problem.
Tell me why everything works like this:


That’s how the script Area2D breaks:

    ┠╴ColorRect   #Background

How can I fix this so that I can add other nodes and the script Area2D doesn’t break?

Incognito | 2022-11-29 05:50