Hi all. I need some help with signals and arguments.
I have:
a global script where I declare global signals (globalsignals.gd)
node A which emits a global signal
node B which receives it
In Node B’s script I say:
func _ready():
var argument: int
globalsignals.my_global_signal.connect(method_to_call.bind(argument))
func method_to_call(argument):
print(argument)
In Node A’s script: globalsignals.emit_signal("my_global_signal", 1)
Judging by the docs, Node A should be emitting the global signal along with the argument 1. What am I doing wrong in Node B that the argument is not getting bound to the callable and not being passed to it?
Thank you.
A little more context wouldn’t hurt. What does your declaration of globalsignals.my_global_signal look like?
Separate thought: could it be an ordering issue of when the connection is setup vs. when it’s emitted? What are you seeing in node b? Is it crashing? Is it getting a signal and somehow no argument? A wrong argument? Nothing at all?
Callable.bind() is used to bind extra parameters to a Callable and are passed after the required parameters of that Callable. If your Signal already emits with 1 parameter you don’t need to bind anything else.
That’s what I thought too, but it doesn’t work. THe Callable doesn’t get called when it’s declared with an argument like this: func callable_method(argument) when the signal that is connected to it has no bound argument.
The signal gets picked up but the method doesn’t trigger.
thanks a lot, I was looking for some answer like this, cause I don’t use binds in a few methods and it works, the reason is that only has 1 arg and just make total sense that just applies to multiple parameters!