Video Game Design and Coding · PLECK lesson

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

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. 1. Implement a request checker with negative, too-large and valid outcomes.
  2. 2. Trace requests -1, 2 and 8 when cargo is 5.

Deliverable. Request-checking script, scene and three traces.

Acceptance checks

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.

Name ____________________ Date ____________________