Guide to the Godot game engine/Signals and methods

Many Godot users will say to you "signal up, call down" if you ask for tips with coding. Just what does this mean?

Signals
Select a node from the Scene dock. Press the "Node" tab next to the inspector. A list will appear. These are signals.

Create a new scene. Press User Interface. Save it as. Add two nodes: a Button and a Label, both as children of the Control. Use the  button to center the Button to the screen. Set the  property to   in the inspector.

Now add a script to the Control root node (the first one). Select the Button. Open the Node dock, and double click "button_up". A popup will appear with your scene root (the Control node) selected. A text edit should say. Press "Connect".

This will create the code



This function will be called when the signal  is emitted. Add the code  to the function. You may remove the  if you wish.

Run the scene by pressing F6, and grant that button's wish!

You can make your own signals with  in GDScript. To emit it in a function:.

Calling
Just as important as signals, calling allows many things to happen. Add  to the function. This is actually setting a variable, but it's still considered calling, as setting a variable uses a setter function. More on those in another chapter.

The  is a short hand for the   function. The  is the path argument. This allows direct manipulation of the child node of that name.

These are called s. They work a bit like file paths, and this is a common example:, and can also be relative, like (called in  ).

A global  looks like.

For more, please see GDScript: Manipulating the SceneTree.

Signal up and call down
It means, if you are calling methods on another node, use signals for calling parents (to decrease code complexity) and use methods when calling children (to increase readability and freedom).

What you have learned

 * 1) How to get a child node.
 * 2) How to connect a signal.
 * 3) How to set a property of another node (With the ".". You can use it to call their functions too!)

Quiz


{What do you use to get a node? } + + -
 * type="[]"

{Are node paths are like file paths? } +Yes -No
 * type=""
 * They support the "../" shorthand.

{Which way are you supposed to call? } +Down -Up
 * type=""
 * That's not saying you can't, just limit how many times you call down.

