Basic syntax for sending a variable between two scripts with signals

Godot Version

4.3

Question

I am brand new to Godot and I am having trouble doing what I think is extremely simple. All I want is script A to send an integer value to script B and then script B to pass that integer through a local function within script B. I feel like this should be insanely simple but I cannot figure out to do it, and chatGPT/deepseek can’t either I assume because they don’t know godot 4.

As a side note can people share tips on how to read documentation? Whenever I want to understand how to do something in godot I go to the documentation first but so far the only thing I was able to learn from it was how to use a match. In this case this is the only thing I could find about signals and I don’t see anything about connecting signals between two different scripts. its really frustrating because I am feeling like I have to rely on AI to learn how stuff works but I don’t want to do that

I typed your question into Perplexity and got an exact answer.

In script A you create a signal and emit it:

signal send_value_signal(value: int)

func _ready():
    send_value_signal.emit(42)

Then in script B you have to connect to the signal like this to a function and recieve the new value:

func _ready():
      NodeWithScriptA.send_value_signal.connect(_on_receive_value)

func _on_receive_value(new_value: int):
       # do whatever you want with the int 'new_value'
       print("Recieved ", new_value)

The documentation has some examples and tutorials but is mostly a reference guide. I use it to look up functions mostly. However in the ‘Getting Started’ section you have a chapter called ‘Step by step’ and in that an entire section with multiple pages on ‘Using signals’, both in the editor and in code, including custom signals like the one above, as well as example scripts to copy and paste.

If you are new to Godot, you should do some tutorials first. Make sure they are simple ones like the ‘Your first 2D game’ in the docs. Don’t rush them, and my advice would be to do them two or three times until you can almost do them from heart, making sure you understand each step in detail. Signals are covered in these too. Also signals are everywhere on YouTube for godot as well. Watch lots of these too.

Also, do not rely on AI, it still hallucinates, will often lead you up the garden path producing overly complex code, sometimes incorrect code, and surprisingly often simply made up functions it claims are built in. But as a first search it is fine, but follow the links provided and always check with the docs.

Good luck.