How nodes talk to each other. Instead of constantly asking “did something happen yet?”, a node can announce it. You'll make your coins announce when they're collected and show a live score.
Two identical levels keep score in different ways. Click the coins to collect them and watch the counters.
Signals are how Godot nodes say “something just happened.”
A node emits a signal when something happens: a Timer runs out (timeout), a body enters an Area2D (body_entered), a button is pressed (pressed).
You connect a signal to a function (method) on any node. When the signal fires, that function runs. One signal can connect to many functions.
Next to the Inspector there's a Signals tab listing every signal the selected node can emit. Double-click one to connect it.
Write signal collected at the top of a script, then collected.emit() whenever it happens. Now anyone can listen to your coin.
Connect signals (⚡) to methods (→) so the level behaves as described. Then test it.
👇 Click a ⚡ signal on the left, then click the → method it should run on the right.
About 15 minutes. Keep working in your project from Basics 5.
_on_body_entered, with a small green icon next to it. That icon means “a signal is connected here.” 💾 Save: Ctrl+Sextends Area2D). If not, click coin.gd in that list. Then select all and replace with this. It adds a signal of its own, removes the Basics 5 overlap check, and fills in the new function:Keep the function name exactly _on_body_entered, since that's what the connection points to. if body is CharacterBody2D means only the player counts, so walls touching a coin no longer collect it.$ScoreLabel means “my child called ScoreLabel,” which is why the name has to match exactly.💾 Save before you run. A (*) on a tab means unsaved changes, which may not show up in the game.
That coin's collected signal isn't connected. Select the coin in main.tscn → Signals tab: a connected signal shows a connection line underneath it. Also check the receiver method is _on_coin_collected, exactly as in main.gd.
Godot can't find $ScoreLabel. The label must be named exactly ScoreLabel (capital S and L, no spaces) and be a direct child of the root Node2D.
The body_entered connection is missing, or the function name changed. In coin.tscn, select Coin → Signals tab and check body_entered shows a connection to _on_body_entered. Redo step 3 if not.
You kept the suggested name. Either redo the connection with _on_coin_collected, or delete the extra function in main.gd and reconnect.
It's in the dock on the right, beside Inspector. Make sure a node is selected in the Scene dock first. Some layouts label it Node with a Signals section inside.
Select all the code and use Edit → Indentation → Convert Indent to Tabs.
“Coins: 0” shows in the top-left corner. Each coin you collect disappears and the number goes up by one. Coins next to walls no longer vanish on their own.
Make one of your coins red and worth 5 points, while the others stay gold and worth 1.
You'll need: an @export setting (Basics 3) and a signal that carries a value. Signals can send information along with the announcement.
Each coin needs its own “how much am I worth” setting that you can change per coin in the Inspector. Then the signal needs to tell main how much to add, not just “I was collected.”
In coin.gd: add @export var value := 1, change the signal to signal collected(amount), and emit it with collected.emit(value). In main.gd, give the function a parameter, func _on_coin_collected(amount), and add amount instead of 1. Then in main.tscn select Coin3: set Value to 5 and Visibility → Modulate to red.
# coin.gd: the changed lines
signal collected(amount) # the signal now carries a number
@export var value := 1 # how many points this coin is worth
func _on_body_entered(body: Node2D) -> void:
if body is CharacterBody2D:
collected.emit(value) # send the value along
queue_free()# main.gd: the changed function
func _on_coin_collected(amount) -> void:
score += amount
$ScoreLabel.text = "Coins: " + str(score)Your existing signal connections keep working, because the function name didn't change. Red tint tip: the Modulate on Coin3 in main.tscn tints just that one coin.
Three questions, then you're done.
You connected built-in signals, made your own, and used them to keep score without any node checking on another every frame.