Video Game Design and Coding

PLECK lesson 51 · suggested week 11, day 1

Turn a story condition into Boolean logic

Objective. Translate a rule with and, or and not.

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.

Booleans, truth tables, inventory flags and testable conditions

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-L050.

A locked archive gate opens when the player has the key, the lever is on and the alarm is off. Those three facts are Booleans. C-PUZZLE expresses the rule with and and not. Parentheses clarify mixed and/or conditions. Write the rule in ordinary language first, then code it, then test it independently of the story interface. Avoid checking visible text such as “Key found” as if it were game state; text can be edited without changing possession.

Worked example

A separate practice door might require badge OR helper_present. Test each Boolean combination on paper before using the function to show an Open button. Scaffold C-PUZZLE — A testable gate rule Setup: Create Node root GateLab and attach this script. The pure gate_open function does not read input or change a scene. A level can call it with its inventory and lever state. Assertions run on start. For the assignment write additional tests before changing the rule. ```gdscript extends Node func gate_open(has_key: bool, lever_on: bool, alarm_on: bool) -> bool: return has_key and lever_on and not alarm_on func _ready() -> void: assert(gate_open(true, true, false)) assert(not gate_open(false, true, false)) assert(not gate_open(true, false, false)) assert(not gate_open(true, true, true)) print("Gate checks passed") ```

A testable gate rule

GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-PUZZLE. Copy starts from this text. The desk does not run it.

Scene and node setup

Create Node root GateLab and attach this script. The pure gate_open function does not read input or change a scene. A level can call it with its inventory and lever state. Assertions run on start. For the assignment write additional tests before changing the rule.

extends Node
func gate_open(has_key: bool, lever_on: bool, alarm_on: bool) -> bool:
    return has_key and lever_on and not alarm_on
func _ready() -> void:
    assert(gate_open(true, true, false))
    assert(not gate_open(false, true, false))
    assert(not gate_open(true, false, false))
    assert(not gate_open(true, true, true))
    print("Gate checks passed")

Checks to run in the editor

  • Four supplied assertions pass.
  • A complete truth table contains eight input combinations.

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.

Turn a story condition into Boolean logic — evidence task

  1. 1. Write the gate rule in words and GDScript.
  2. 2. Test the four supplied combinations and one additional combination.

Deliverable. GateLab source and five-case result table.

Acceptance checks

  • VGC-L051-T1. The gate opens only when all required conditions hold.
  • VGC-L051-T2. The function returns a Boolean without changing inventory.

Understanding question. Does having the key alone open this gate?

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 the C-PUZZLE pure function and a paper truth table before attaching conditions to UI. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.

Optional extra. Find a logically equivalent expression and verify all eight truth-table rows. 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.

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.

Print this lesson