PLECK lesson 23 · suggested week 5, day 3
Let the level own the score
Objective. Connect a signal to a single authoritative state variable.
Godot Engine Standard desktop editor 4.7.2-stable, GDScript (Godot 4), Compatibility renderer. Headless Godot 4.7.2.stable.official.ed1daf0bf passed 106 assertions on the supplied scaffolds, including malformed JSON saves. Audio used the Dummy driver and a synthetic WAV, not a speaker. The visual editor, browser export, and signed-in submission were not tested. The desk still does not run a student's own upload.
About 55 minutes. The due date is chosen by a parent.
Area2D signals, groups, exactly-once events and a HUD
Suggested pace: Recall and predict 5 min; Read instruction and scaffold 12 min; Build or design the assigned artifact 25 min; Run acceptance tests 8 min; Explain and checkpoint 5 min.
Materials: Godot Standard 4.7.2 desktop editor (GDScript, Compatibility renderer), Local course folder and prior checkpoint, No paid assets or public account required.
Comes after VGC-L022.
A coin should announce its points without knowing where the HUD lives. The World manager owns the round’s score and connects each coin’s collected signal to one handler. This keeps a reusable pickup from depending on a fragile node path into the level. Begin with three fixed coins rather than random spawning. Read C-MANAGER’s loop: each coin connects the same signal to _on_collected. Start score at zero when the scene is created and add points only inside that one handler.
Worked example
A pickup emits collected(1); a manager receives that event and changes one score variable. The label formats that score rather than keeping a second independent total. Scaffold C-MANAGER — A complete three-coin collection round Setup: Create World Node2D root with Player (C-BODY), three Coin instances (C-PICKUP), and CanvasLayer HUD > Label named Score plus Button named Restart (text Restart, position 500,10). Root and parents unscaled. Name coins Coin1, Coin2, Coin3. Place them at (250,100),(380,220),(520,100). Player group player. Attach script to World. UI paths and coin names must match exactly. Connect nothing else in the editor. Label at (10,10). ```gdscript extends Node2D var score: int = 0 var playing: bool = true @onready var score_label: Label = $HUD/Score func _ready() -> void: $HUD/Restart.pressed.connect(_restart) for coin in [$Coin1, $Coin2, $Coin3]: coin.collected.connect(_on_collected) _refresh() func _on_collected(points: int) -> void: if not playing: return score += points if score >= 3: playing = false $Player.set_physics_process(false) _refresh() func _refresh() -> void: score_label.text = "Score: %d / 3" % score if not playing: score_label.text += " — Orchard complete!" func _restart() -> void: get_tree().reload_current_scene() ``` Scaffold C-PICKUP — An exactly-once pickup signal Setup: Create Area2D root Coin, CollisionShape2D Circle radius 10. Layer 3 (bit value 4), mask layer 1 only. Monitoring on. Attach script and save Coin.tscn. In the Node > Groups editor add Player root to group player. Put a Coin instance and Player instance in World. Manager connects each Coin.collected to its score handler (see C-MANAGER). Signal wiring here is code-only: do not also connect body_entered in editor. ```gdscript extends Area2D signal collected(points: int) @export var points: int = 1 var taken: bool = false func _ready() -> void: body_entered.connect(_on_body_entered) func _draw() -> void: draw_circle(Vector2.ZERO, 10.0, Color.GOLD) draw_line(Vector2(-5, 0), Vector2(5, 0), Color.BLACK, 2.0) func _on_body_entered(body: Node2D) -> void: if taken or not body.is_in_group("player"): return taken = true collected.emit(points) queue_free() ```
A complete three-coin collection round
GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-MANAGER. Copy starts from this text. The desk does not run it.
Scene and node setup
Create World Node2D root with Player (C-BODY), three Coin instances (C-PICKUP), and CanvasLayer HUD > Label named Score plus Button named Restart (text Restart, position 500,10). Root and parents unscaled. Name coins Coin1, Coin2, Coin3. Place them at (250,100),(380,220),(520,100). Player group player. Attach script to World. UI paths and coin names must match exactly. Connect nothing else in the editor. Label at (10,10).
extends Node2D
var score: int = 0
var playing: bool = true
@onready var score_label: Label = $HUD/Score
func _ready() -> void:
$HUD/Restart.pressed.connect(_restart)
for coin in [$Coin1, $Coin2, $Coin3]:
coin.collected.connect(_on_collected)
_refresh()
func _on_collected(points: int) -> void:
if not playing:
return
score += points
if score >= 3:
playing = false
$Player.set_physics_process(false)
_refresh()
func _refresh() -> void:
score_label.text = "Score: %d / 3" % score
if not playing:
score_label.text += " — Orchard complete!"
func _restart() -> void:
get_tree().reload_current_scene()
Checks to run in the editor
- Collect three coins: score is 3 and a completion message appears.
- Restart recreates three coins and score is zero.
Native Godot 4.7.2.stable.official.ed1daf0bf headless compile and representative node-tree/runtime tests passed; see native-qa-results.json. Visual UI, audible output, exports and website submission still need separate checks.
An exactly-once pickup signal
GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-PICKUP. Copy starts from this text. The desk does not run it.
Scene and node setup
Create Area2D root Coin, CollisionShape2D Circle radius 10. Layer 3 (bit value 4), mask layer 1 only. Monitoring on. Attach script and save Coin.tscn. In the Node > Groups editor add Player root to group player. Put a Coin instance and Player instance in World. Manager connects each Coin.collected to its score handler (see C-MANAGER). Signal wiring here is code-only: do not also connect body_entered in editor.
extends Area2D
signal collected(points: int)
@export var points: int = 1
var taken: bool = false
func _ready() -> void:
body_entered.connect(_on_body_entered)
func _draw() -> void:
draw_circle(Vector2.ZERO, 10.0, Color.GOLD)
draw_line(Vector2(-5, 0), Vector2(5, 0), Color.BLACK, 2.0)
func _on_body_entered(body: Node2D) -> void:
if taken or not body.is_in_group("player"):
return
taken = true
collected.emit(points)
queue_free()
Checks to run in the editor
- A player touching the coin emits once and removes it.
- A wall or hazard touching the coin does not collect.
Native Godot 4.7.2.stable.official.ed1daf0bf headless compile and representative node-tree/runtime tests passed; see native-qa-results.json. Visual UI, audible output, exports and website submission still need separate checks.
Pocket Orchard starter, as text files. Open the files in Godot on the family computer. This page does not download a zip or run the project.
Let the level own the score — evidence task
- 1. Build the named World children required by C-MANAGER.
- 2. Connect all three coins and print score changes in the handler.
Deliverable. Three-coin manager project and score trace.
Acceptance checks
- VGC-L023-T1. Collecting coins produces 1, then 2, then 3.
- VGC-L023-T2. Moving without collection does not change score.
Understanding question. Why should each coin not keep its own copy of the total score?
Include a downloadable project ZIP with project.godot, .tscn, .gd and original asset files when code changes. A private, teacher-accessible download link to that ZIP is equivalent. Screenshots or a playthrough do not replace editable source.
If this is still shaky. Use one coin and one player in a blank World. Confirm the group and mask before adding a score label. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
Optional extra. Add a second pickup value using the same signal instead of duplicating the whole scene. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.
Turn in typed notes and a JPEG, PNG, or WebP screenshot. One https address is stored as text and is not opened, extracted, or run. An MP3, WAV, M4A, MP4, or WebM file up to 4 MB can show a demo. The demo does not replace editable source. Zip and code files are refused. If there is no private link, keep the project on the family computer and review the code in person.
- Godot step by step: nodes, scenes, GDScript, input, signals
Free public documentation, no account. Same class help is available within the desktop editor.
· Opening this link does not submit the lesson.
This is a preview. A parent assigns the lesson and chooses the due date after the student is enrolled. The answer key is not on this page.
