Emit_signal ignored

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hide

Hi,
I have many “Pawn”, “Pawn1”… scene instances in my game, i’d like to be able to select only one at once with a mouse left click. Right click would also be deselecting the one.
But when i left click on one and then another it select the second while letting the first selected.
Right click does unselect all as intended.

func _on_Area2D_mouse_entered():
	selectable = true

func _on_Area2D_mouse_exited():
	selectable = false

func _input(event):
	if event is InputEventMouseButton and event.button_index == 1 and selectable:
		emit_signal("unselect")
        selected = true
		
	if event is InputEventMouseButton and event.button_index == 2:
		emit_signal("unselect")

func _on_Area2D_unselect():
	selected = false

EDIT : Actually while trying to explain the problem I found the solution, i had to do this :

if event is InputEventMouseButton and event.button_index == 1:
	emit_signal("unselect")
	if selectable:
		selected = true

But can someone explain to me why would the conditions prevent the signal to be propagated to other instances that (i think) should just execute the received signal in _on_Area2D_unselect() ?

:bust_in_silhouette: Reply From: matelike

Pawn? What its mean?

It’s only an area2D, named “Pawn” (like in chess).

hide | 2020-10-28 18:25

The exemple code is cleaned with the actual Godot class if that was what caused the downvotes…

hide | 2020-10-29 16:57