Museum of Lost Lights · Lesson 42 of 50 · Advanced · About 40 min
The moth is glowing on your computer. Invite someone who has never solved your puzzle to try it, and watch what they do without showing them the route.

Download the projects from the course page. In Godot’s Project Manager, choose Import, select project.godot, and use Run Project (F5). Start from checkpoints/41 when the lesson builds on prior work, or copy the checkpoints/42 folder to try this lesson on its own. Read the file names in the steps before editing.

Build it step by step
Language and tools in this lesson static tests, Array[Dictionary], Dictionary dot access, comparison with ==, counter += 1, join, regression tests.
-
Open the checkpoint in Godot
Extract the course files. In Godot Project Manager, choose Import and point it to this lesson’s project.godot. Double-click main.gd in FileSystem to open the script. Press F6 to run the current scene once main.tscn is open, or F5 to run the project. Press Run simulator checks. The list shows both the expected result and the result the rules returned.
const UI = preload("res://lesson_ui.gd")Why it works This small project lets you see one release skill at a time. The finished Museum of Lost Lights is a second, independent project. Keep both projects in their own folders.
-
List four small cases
Find EXAMPLES. Each dictionary names a test and stores two inputs and one prediction. Verify the combinations false/false, true/false, false/true and true/true.
{"name": "Two mirrors", "a": true, "b": true, "expected": true},Why it works A small table covers the whole two-mirror gate. When you add a rule, rerun these examples so you notice if an old behaviour breaks.
-
Keep game logic separate from the screen
Open gate_is_open. Check that it accepts two bool values and returns one bool. It reads no Buttons or text labels.
return a and bWhy it works A function that only uses inputs is easy to rerun with many examples. The real game can still use a result to change its animation.
-
Compare the prediction with the actual result
Inside _run_checks, follow one example through the loop. Compare actual and sample.expected with ==. Try temporarily changing one expected answer in your copy, then rerun and read the FAIL line. Undo the change and rerun.
var passed: bool = actual == sample.expectedWhy it works The equals signs compare two results. Pass counts grow only when the result and prediction match.
-
Use a device test card
Choose Godot’s embedded game window or resize its standalone game window first. When you have a real device build from lesson 44 or 45, test on the smallest phone available and on a second screen. Try a first launch, ten rapid taps, mute, leaving the app and returning, closing it and reopening, and playing offline.
Why it works A simulator can check the puzzle rules. Touch reach, text clipping, rotation, saving and device performance need separate checks on real hardware.
-
Run one observed playtest
Give the phone to a tester and say, ‘Wake the moth’. Write down the first tap, where they hesitate, what they expect, and one concrete change. Run your same script checks and device checks after making the change.
Why it works An observed test shows whether another person can understand the game’s clues without your help.
-
Read the result, then apply it to your game
Give each issue a short name, a numbered replay path and the actual and expected result. Include device model, operating system and build number without adding the tester’s name or private details.
Why it works The checkpoint shows what to look for. Your game’s real result comes from testing your own build, assets and settings.
Watch the values change
-
Test empty room Inputs false, false. Expected false.
What you see. The result is false and the example passes. -
Test one mirror Inputs true, false. Expected false.
What you see. The gate stays shut and the example passes. -
Test successful route Inputs true, true. Expected true.
What you see. The gate opens and the example passes.
Predict before you run If you replace the function body with return a or b, which examples should fail?
Reveal the answer
Both one-mirror cases fail. Each uses one true value, so or gives true while the examples still expect a shut gate.
Complete checkpoint
Clicking Run simulator checks displays 4 of 4 rule checks passed plus four PASS lines.
main.gd
extends Control
const UI = preload("res://lesson_ui.gd")
const EXAMPLES: Array[Dictionary] = [
{"name": "No mirrors", "a": false, "b": false, "expected": false},
{"name": "Only A", "a": true, "b": false, "expected": false},
{"name": "Only B", "a": false, "b": true, "expected": false},
{"name": "Two mirrors", "a": true, "b": true, "expected": true},
]
var output: Label
func _ready() -> void:
var column := UI.build(self, "Museum playtest lab", "Check the rule, then playtest the real gallery on a device.")
UI.button(column, "Run simulator checks", _run_checks)
output = UI.message(column, "No checks run yet.")
func gate_is_open(a: bool, b: bool) -> bool:
return a and b
func _run_checks() -> void:
var lines := PackedStringArray()
var pass_count := 0
for sample in EXAMPLES:
var actual := gate_is_open(sample.a, sample.b)
var passed: bool = actual == sample.expected
if passed:
pass_count += 1
var mark := "PASS" if passed else "FAIL"
lines.append("%s: %s, expected %s, returned %s." % [mark, sample.name, sample.expected, actual])
output.text = "%d of %d rule checks passed.\n%s" % [pass_count, EXAMPLES.size(), "\n".join(lines)]
lesson_ui.gd
extends RefCounted
static func build(screen: Control, heading: String, opening: String) -> VBoxContainer:
var margins := MarginContainer.new()
screen.add_child(margins)
margins.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
for edge in ["left", "right", "top", "bottom"]:
margins.add_theme_constant_override("margin_" + edge, 24)
var scroll := ScrollContainer.new()
margins.add_child(scroll)
var column := VBoxContainer.new()
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
scroll.add_child(column)
column.add_theme_constant_override("separation", 12)
var title := Label.new()
title.text = heading
title.add_theme_font_size_override("font_size", 30)
column.add_child(title)
message(column, opening)
return column
static func message(column: VBoxContainer, text: String) -> Label:
var line := Label.new()
line.text = text
line.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
column.add_child(line)
return line
static func button(column: Container, caption: String, action: Callable) -> Button:
var control := Button.new()
control.text = caption
control.custom_minimum_size.y = 48
control.pressed.connect(action)
column.add_child(control)
return control
GDScript line by line
Follow the line numbers, including the indent at the start of each line. Find the code the game will run first, then look for the function that reacts when you tap or change something.
Read main.gd line by line
-
extends ControlStarts with Godot's Control type. This script gets the abilities of that type and adds the game's own rules. -
const UI = preload("res://lesson_ui.gd")Creates a constant named UI. The expression prepares a resource at a fixed project path when the script is loaded. -
const EXAMPLES: Array[Dictionary] = [Creates a constant named EXAMPLES. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
{"name": "No mirrors", "a": false, "b": false, "expected": false},Starts a list or dictionary used as part of the instruction above. -
{"name": "Only A", "a": true, "b": false, "expected": false},Starts a list or dictionary used as part of the instruction above. -
{"name": "Only B", "a": false, "b": true, "expected": false},Starts a list or dictionary used as part of the instruction above. -
{"name": "Two mirrors", "a": true, "b": true, "expected": true},Starts a list or dictionary used as part of the instruction above. -
]Closes the parentheses, list or dictionary opened above. Any trailing comma separates this item from the next. -
var output: LabelDeclares output for later use. A colon followed by a type says which kind of value belongs here. -
func _ready() -> void:Godot calls this once after the scene and its children are ready. Use it to set up the room and connect controls. -
var column := UI.build(self, "Museum playtest lab", "Check the rule, then playtest the real gallery on a device.")Creates a variable named column. The expression calls UI.build with the values in its parentheses. Godot infers the type from the first value. -
UI.button(column, "Run simulator checks", _run_checks)Calls UI.button with the values in its parentheses. -
output = UI.message(column, "No checks run yet.")Stores the new value in output. The expression calls UI.message with the values in its parentheses. -
func gate_is_open(a: bool, b: bool) -> bool:Defines gate is open, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
return a and bFinishes the function and hands its result back to the caller. The expression evaluates the test to see whether it is true or false. -
func _run_checks() -> void:Defines run checks, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var lines := PackedStringArray()Creates a variable named lines. The expression calls PackedStringArray with the values in its parentheses. Godot infers the type from the first value. -
var pass_count := 0Creates a variable named pass_count. The expression uses the whole number 0. Godot infers the type from the first value. -
for sample in EXAMPLES:Repeats the indented instructions for each value in EXAMPLES. -
var actual := gate_is_open(sample.a, sample.b)Creates a variable named actual. The expression calls gate_is_open with the values in its parentheses. Godot infers the type from the first value. -
var passed: bool = actual == sample.expectedCreates a variable named passed. The expression evaluates the test to see whether it is true or false. The type after the colon says what kind of value it can hold. -
if passed:Checks passed. The indented instructions below run only if this test passes. -
pass_count += 1Reads pass_count, adds to its old value, then stores the result back in the same place. -
var mark := "PASS" if passed else "FAIL"Creates a variable named mark. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
lines.append("%s: %s, expected %s, returned %s." % [mark, sample.name, sample.expected, actual])Adds an item to the end of a list. -
output.text = "%d of %d rule checks passed.\n%s" % [pass_count, EXAMPLES.size(), "\n".join(lines)]Updates output.text, which controls the words a player sees. The expression uses the text inside the quotes.
Read lesson_ui.gd line by line
-
extends RefCountedStarts with Godot's RefCounted type. This script gets the abilities of that type and adds the game's own rules. -
static func build(screen: Control, heading: String, opening: String) -> VBoxContainer:Defines build, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var margins := MarginContainer.new()Creates a variable named margins. The expression creates a new MarginContainer object. Godot infers the type from the first value. -
screen.add_child(margins)Adds the new node to the scene tree so that Godot can run and draw it. -
margins.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Positions this Control relative to the bounds of its parent. -
for edge in ["left", "right", "top", "bottom"]:Repeats the indented instructions for each value in ["left", "right", "top", "bottom"]. -
margins.add_theme_constant_override("margin_" + edge, 24)Calls margins.add_theme_constant_override with the values in its parentheses. -
var scroll := ScrollContainer.new()Creates a variable named scroll. The expression creates a new ScrollContainer object. Godot infers the type from the first value. -
margins.add_child(scroll)Adds the new node to the scene tree so that Godot can run and draw it. -
var column := VBoxContainer.new()Creates a variable named column. The expression creates a new VBoxContainer object. Godot infers the type from the first value. -
column.size_flags_horizontal = Control.SIZE_EXPAND_FILLStores the new value in column.size_flags_horizontal. The expression reads Control.SIZE_EXPAND_FILL. -
scroll.add_child(column)Adds the new node to the scene tree so that Godot can run and draw it. -
column.add_theme_constant_override("separation", 12)Calls column.add_theme_constant_override with the values in its parentheses. -
var title := Label.new()Creates a variable named title. The expression creates a new Label object. Godot infers the type from the first value. -
title.text = headingUpdates title.text, which controls the words a player sees. The expression reads heading. -
title.add_theme_font_size_override("font_size", 30)Calls title.add_theme_font_size_override with the values in its parentheses. -
column.add_child(title)Adds the new node to the scene tree so that Godot can run and draw it. -
message(column, opening)Calls message with the values in its parentheses. -
return columnFinishes the function and hands its result back to the caller. The expression reads column. -
static func message(column: VBoxContainer, text: String) -> Label:Defines message, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var line := Label.new()Creates a variable named line. The expression creates a new Label object. Godot infers the type from the first value. -
line.text = textUpdates line.text, which controls the words a player sees. The expression reads text. -
line.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTStores the new value in line.autowrap_mode. The expression reads TextServer.AUTOWRAP_WORD_SMART. -
column.add_child(line)Adds the new node to the scene tree so that Godot can run and draw it. -
return lineFinishes the function and hands its result back to the caller. The expression reads line. -
static func button(column: Container, caption: String, action: Callable) -> Button:Defines button, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var control := Button.new()Creates a variable named control. The expression creates a new Button object. Godot infers the type from the first value. -
control.text = captionUpdates control.text, which controls the words a player sees. The expression reads caption. -
control.custom_minimum_size.y = 48Stores the new value in control.custom_minimum_size.y. The expression uses the whole number 48. -
control.pressed.connect(action)Links a signal to the function that should run when the event happens. -
column.add_child(control)Adds the new node to the scene tree so that Godot can run and draw it. -
return controlFinishes the function and hands its result back to the caller. The expression reads control.
Find and fix a bug
If your test list is blank, check that _run_checks is connected to a button in _ready, and that the loop appends each line before joining them into the label.
Try a change
Ages 10–12: add a written test for fast double-tapping. Ages 13–16: make a new test for your original rule, break the rule deliberately in a copy and confirm that the test catches it.