+2 votes

I have a main node script and a child node script.
And I want to generate a value on mouse movement, store it in a variable Type and send this variable to a child node where it will be used as a reference to a dictionary.

On the main node I have this:

var Type
signal Send_signal
func _ready():
    connect("Send_signal", get_node("child"), "Set_type", [Type])
func _on_Area_mouse_entered(): 
    Type = *Generated by a function value*
    emit_signal("Send_signal")

And on the child node I have

func Set_type(Type):
    Class = Type["name"]
var *Generated by a function value* = {name = "bob"}

Clearly a missed something in the process of understanding of how to create a custom signal. Can you tell me what?

in Engine by (88 points)

the syntax for connect is connect("signal_name", signal_target_node, "signal_function") Then emit should go like emit_signal("signal_name", [argument]). Inside those brackets put the arguments of the function. Then in signal_target_node, for you it'd be your child node, put func signal_function(argument1): The parameters to your signal function should be in emit_signal not connect

emit_signal("signal_name", [argument])

It doesn't looks like you need brackets there. Or it will send it just like that, as "[argument]"
But thank you anyway.

1 Answer

+4 votes
Best answer

There are two ways to send values through signals: arguments, and bindings.

1) Arguments are values sent at the moment the signal is emitted, pretty much like function calls.

2) Bindings are values coming from the moment you connected the signal (and won't change after). Those are rarely needed, but sometimes they come in handy.

At the moment the signal is emitted, they are both put together: arguments first, bindings next, and are sent to the handling functions.

It looks like you need the first, but you used the second instead, which means the signal will always emit with the value Type had at the moment you connected the signal. So it's always null.
To make the signal emit with the current value of Type, declare your signal like this:

signal Send_signal(type)

And emit it like this:

emit_signal("Send_signal", Type)

I would have linked the doc: https://docs.godotengine.org/en/3.1/getting_started/step_by_step/signals.html#signals
Unfortunately, it seems signal parameters are not explained.

by (28,982 points)
selected by

Thank you. Now it works.

Unfortunately, it seems signal parameters are not explained.

Indeed. That is what led me to googling other people's explanations. But your is as clear and simple as it should be.

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.