From f044f2607e0801e1d2a1d946b9849a67abca03ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnnie=20H=C3=A5rd?= <9264787+johnniehard@users.noreply.github.com> Date: Tue, 3 Mar 2020 22:50:07 +0100 Subject: [PATCH] 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. --- getting_started/step_by_step/signals.rst | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/getting_started/step_by_step/signals.rst b/getting_started/step_by_step/signals.rst index 493cfd2b4..938f75caf 100644 --- a/getting_started/step_by_step/signals.rst +++ b/getting_started/step_by_step/signals.rst @@ -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 ----------