How do I get signal parameters from a child node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mauricio Vera
:warning: Old Version Published before Godot 3 was released.

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():

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):

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

:bust_in_silhouette: Reply From: Warlaan

Your signal declaration (line 3 in the unit script) doesn’t specify any parameters. Change it to

signal select(id)

That will take care of the error message that you get in the map script. What you are doing now is binding your own id to replace the one missing in the signal, but of course that way you always call on_unit_select with the contents of the local id variable.


I should also point out that in order to get it working I had to delete the id in lion.connect("select", self, "on_unit_select", [id]), apparently it only works if you pass an “empty” array?

Mauricio Vera | 2016-07-04 02:09