I'm making a tactical RPG and I want to emit a signal when a unit is pressed and make the map receive that signal.
It's working but I can't get the signal parameters, which I need to identify what unit was pressed.
The unit
extends Area2D
signal select
func _ready():
set_process_unhandled_input(true)
pass
func _input_event(viewport, event, shape_idx):
if event.type == InputEvent.MOUSE_BUTTON \
and event.button_index == BUTTON_LEFT \
and event.pressed:
emit_signal("select", self.get_instance_ID())
The map
extends TileMap
var id = 0
onready var lion = get_node("lion")
func _ready():
lion.connect("select", self, "on_unit_select", [id])
func on_unit_select(id):
print(id)
If I don't declare id
I get an Identifier not found
error, and if I declare it I get an error that says that the method on_unit_select
was expecting 1 argument, meaning that the id = 0
is not getting passed to the function