The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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

in Engine by (18 points)
edited by

1 Answer

+1 vote
Best answer

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.

by (1,124 points)
selected by


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?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.