compsci_godot_albert/_subsections/sec03/lesson-11.org
2025-07-17 01:33:06 +03:00

2.7 KiB
Executable file

Section 03 - Lesson 11, 12 | Signals, Custom Signals

Notes

Signals

  • messaging system
  • way of communicating between nodes

connect basics

  • means of connecting

    • ide
    • code
  • the node giving the signal has a list of everyone that connected

connecting via ide

  1. select Node panel on leftside, and then select the approrpiate signal

    • /notes/compsci_godot_albert/media/commit/c59e28d3a8156577ead9c279e579c5a5753c19e2/_share/media/img/albert/section03/S03_L11_EX01.png
  2. double click the selected filter

    • options available:

      • from signal
      • connect to script
      • receiver method

        • you can also click on "Pick" next to receiver method so that you can choose a different method that already exists
  3. click connect and the boilerplate code will appear in the script you had selected in the signal creation pane above in (2)

    • if you look at the node pane on the right and scroll to the signal, you'll see a green indicator showing that you have connected that signal (to something)

      • /notes/compsci_godot_albert/media/commit/c59e28d3a8156577ead9c279e579c5a5753c19e2/_share/media/img/albert/section03/S03_L11_EX02.png
    • similarly, you can see a green icon by the function in the code editor

      • /notes/compsci_godot_albert/media/commit/c59e28d3a8156577ead9c279e579c5a5753c19e2/_share/media/img/albert/section03/S03_L11_EX03.png

Custom Signals

declare the signal

to create a signal, use the following format:

signal name_of_signal

activate the signal

name_of_signal.emit()

register to signal

  • go to the scene you want to attach the signal to
  • pick the node
  • the signal should be available under Inspector->Node->Signals
  • connect the signal, and give the function a name you want, this will be your receiver function

    • if you want to attach another node to the same receiver function, use "pick" when connecting the signal

      • /notes/compsci_godot_albert/media/commit/c59e28d3a8156577ead9c279e579c5a5753c19e2/_share/media/img/albert/section03/S03_L12_EX01.png
  • if you have more than one node connected to a receiver function you can see which are connected by clicking on the green icon next to the receiver function

    • /notes/compsci_godot_albert/media/commit/c59e28d3a8156577ead9c279e579c5a5753c19e2/_share/media/img/albert/section03/S03_L12_EX02.png