Show how to pass a value with a signal (#2886)

I had some trouble finding how to do this in the documentation, but had seen it used in some youtube tutorial. I think it would be fitting to explain the usage on this page.

I do not know the corresponding C# syntax, so I haven't changed that part.
This commit is contained in:
Johnnie Hård
2020-03-03 22:50:07 +01:00
committed by GitHub
parent 52026c1a0a
commit f044f2607e
+50
View File
@@ -204,6 +204,56 @@ To emit a signal via code, use the ``emit_signal`` function:
EmitSignal(nameof(MySignal));
}
}
A signal can also optionally declare one or more arguments. Specify the
argument names between parentheses:
.. tabs::
.. code-tab:: gdscript GDScript
extends Node
signal my_signal(value, other_value)
.. code-tab:: csharp
public class Main : Node
{
[Signal]
public delegate void MySignal();
}
.. note::
The signal arguments show up in the editor's node dock, and Godot
can use them to generate callback functions for you. However, you can still
emit any number of arguments when you emit signals. So it's up to you to
emit the correct values.
To pass values, add them as the second argument to the ``emit_signal`` function:
.. tabs::
.. code-tab:: gdscript GDScript
extends Node
signal my_signal(value, other_value)
func _ready():
emit_signal("my_signal", true, 42)
.. code-tab:: csharp
public class Main : Node
{
[Signal]
public delegate void MySignal();
public override void _Ready()
{
EmitSignal(nameof(MySignal));
}
}
Conclusion
----------