PLECK lesson 9 · suggested week 2, day 4
Branch on a legal decision
Objective. Use if, elif and else to make exclusive outcomes.
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.
Values, types, expressions, branches and repeatable experiments
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-L008.
A condition chooses which block runs. For a delivery request, first reject a negative quantity, then reject a quantity greater than the bag’s cargo, otherwise accept it. The order prevents a negative request from adding items by subtraction. In GDScript a colon starts each branch and indentation determines its contents. An if/elif/else chain selects at most one branch. Two unrelated if statements can both run, which may be wrong for mutually exclusive outcomes. Start with printed messages before changing any stored cargo.
Worked example
A counter lab can store parcels as an int and route_title as a String. print exposes intermediate values; a function such as double_points(n) returns n*2 without needing any artwork. Scaffold C-HELLO — An observable first script Setup: Create a Node scene, name root Lab, attach lab.gd. Save as lab.tscn. Run current scene (editor clapboard/Run Current Scene). Output panel shows print output. All unindented lines belong to the script and indented lines belong to the function. ```gdscript extends Node var deliveries: int = 0 func _ready() -> void: deliveries += 1 print("Deliveries: ", deliveries) ```
An observable first script
GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-HELLO. Copy starts from this text. The desk does not run it.
Scene and node setup
Create a Node scene, name root Lab, attach lab.gd. Save as lab.tscn. Run current scene (editor clapboard/Run Current Scene). Output panel shows print output. All unindented lines belong to the script and indented lines belong to the function.
extends Node
var deliveries: int = 0
func _ready() -> void:
deliveries += 1
print("Deliveries: ", deliveries)
Checks to run in the editor
- Run once: Deliveries: 1
- Stop and run: value is 1, not 2.
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.
Branch on a legal decision — evidence task
- 1. Implement a request checker with negative, too-large and valid outcomes.
- 2. Trace requests -1, 2 and 8 when cargo is 5.
Deliverable. Request-checking script, scene and three traces.
Acceptance checks
- VGC-L009-T1. Each request prints exactly one outcome.
- VGC-L009-T2. Only the valid request can reduce cargo.
Understanding question. Why can two separate if statements differ from if/elif?
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. Return to C-HELLO and change one value per run. Write the expected output before running. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
Optional extra. Create another small numeric example and predict the result without executing it first. 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 4.7.2 stable archive and platform downloads
Free public page; download required once for offline desktop use; no account required.
· Opening this link does not submit the lesson. - 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.
