Museum of Lost Lights · Lesson 17 of 50 · Intermediate · About 43 min
A second gallery opens. Now lantern routes need two mirrors. Store what makes each room different on a data card while reusing the game’s controls.

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/16 when the lesson builds on prior work, or copy the checkpoints/17 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 Dictionary, Array of dictionaries, keys, get and fallback values, reuse, modulo wrap, queue_free.
-
Read the two layout cards
Open main.gd and find ROOMS. Check that each dictionary contains a name, dimensions, lamp address, heading number, mirror addresses and target addresses. Draw the Fossil Passage on a new grid using source 10, mirrors 12 and 7, and target 9.
"direction": 1, "mirrors": {12: 1, 7: 1}, "targets": [9]},Why it works An array stores the rooms in order. Each dictionary connects named keys such as width to their values. A dictionary inside mirrors uses tile numbers as keys and initial slants as values.
-
Load the chosen room into its own state
Find _load_room. Notice which values come from ROOMS and which list is cleared. Watch the Godot Remote Scene view before and after changing rooms if you can.
layout = ROOMS[index]Why it works layout stores a reference to a room’s fixed settings, while rotations keeps the player’s changes. queue_free asks Godot to delete the old tiles safely after the current work, and remove_child detaches them immediately.
-
Look up a mirror’s current slant
Read _orientation_at from the innermost get outwards. Trace tile 7 with an empty rotations dictionary, then pretend the player has stored 0 under key 7.
return int(rotations.get(index, layout["mirrors"].get(index, 0)))Why it works The inner get finds the original slant. The outer get gives priority to the player’s stored turn, using the original value as a fallback.
-
Reuse the same ray on the new grid
In _trace_beam, find the source and heading read from layout and the call to _can_turn. Run the project. Solve Ocean, press Next room and try mirrors 12 and 7 in Fossil Passage.
var heading: Vector2i = [NORTH, EAST, SOUTH, WEST][int(layout["direction"])]Why it works The key direction selects a vector from the compass list. The mirror test now uses the map’s keys, so any marked tile can affect the path.
-
Wrap back from the last room
Read _next_room. Try Next room before you win. Then finish both rooms and press Next room twice, once on each success.
_load_room((room_index + 1) % ROOMS.size())Why it works The guard keeps the next room locked while the current room is unfinished. The remainder sends 2 back to index 0 when the room count is 2.
-
Show which room the player is in
Read both status branches in _render. Compare the text after opening the room and after a win. Find where the %s marker is replaced with the room’s name.
status.text = "%s complete!" % str(layout["name"])Why it works The % operator also formats strings when there is text on the left. %s marks a place for the name converted to a String.
Watch the values change
-
Load room 0 layout is Ocean and rotations is empty
What you see. Mirror 12 uses its initial slant 1. -
Solve Ocean and continue room_index becomes 1
What you see. The grid rebuilds with mirrors 12 and 7 and goal 9. -
Turn 12 then 7 rotations becomes {12: 0, 7: 0}
What you see. The beam turns north and then east, reaching goal 9.
Predict before you run After loading Fossil Passage, what slant does tile 12 have before the player touches it?
Reveal the answer
It has slant 1. The room loader cleared rotations, so the lookup reads the Fossil Passage default.
Complete checkpoint
Ocean and Fossil Passage are playable rooms using the same buttons and beam loop. Solve Ocean with tile 12, then solve Fossil Passage with 12 and 7 before returning to Ocean.
main.gd
extends Control
const ROOMS := [
{"name": "Ocean Gallery", "width": 5, "height": 5, "source": 10,
"direction": 1, "mirrors": {12: 1}, "targets": [2]},
{"name": "Fossil Passage", "width": 5, "height": 5, "source": 10,
"direction": 1, "mirrors": {12: 1, 7: 1}, "targets": [9]},
]
const EAST := Vector2i(1, 0)
const SOUTH := Vector2i(0, 1)
const NORTH := Vector2i(0, -1)
const WEST := Vector2i(-1, 0)
var grid: GridContainer
var status: Label
var tiles: Array[Button] = []
var active_path: Array[int] = []
var won := false
var room_index := 0
var layout: Dictionary
var rotations: Dictionary = {}
func _ready() -> void:
var background := ColorRect.new()
background.color = Color("#102a3b")
background.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(background)
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
var centre := CenterContainer.new()
add_child(centre)
centre.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
var page := VBoxContainer.new()
page.add_theme_constant_override("separation", 8)
centre.add_child(page)
var heading := Label.new()
heading.text = "Museum of Lost Lights"
heading.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
heading.add_theme_font_size_override("font_size", 26)
page.add_child(heading)
var subheading := Label.new()
subheading.text = "Tap or keyboard-focus a mirror. Press the mirror to turn it."
subheading.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
page.add_child(subheading)
grid = GridContainer.new()
grid.columns = int(ROOMS[0]["width"])
grid.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
page.add_child(grid)
status = Label.new()
status.custom_minimum_size.x = 460
status.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
page.add_child(status)
var actions := HBoxContainer.new()
actions.alignment = BoxContainer.ALIGNMENT_CENTER
page.add_child(actions)
_add_action(actions, "Hint", _show_hint)
_add_action(actions, "Reset", _reset)
_add_action(actions, "Help", _show_help)
_add_action(actions, "Next room", _next_room)
_load_room(0)
func _make_tiles() -> void:
for index in range(int(layout["width"]) * int(layout["height"])):
var tile := Button.new()
tile.custom_minimum_size = Vector2(60, 48)
tile.focus_mode = Control.FOCUS_ALL
tile.pressed.connect(_tap_tile.bind(index))
tiles.append(tile)
grid.add_child(tile)
func _tap_tile(index: int) -> void:
if won or not _can_turn(index):
return
var current := _orientation_at(index)
rotations[index] = 1 - current
_render()
func _to_index(cell: Vector2i) -> int:
return cell.y * int(layout["width"]) + cell.x
func _to_cell(index: int) -> Vector2i:
@warning_ignore("integer_division")
var row := index / int(layout["width"])
return Vector2i(index % int(layout["width"]), row)
func _inside(cell: Vector2i) -> bool:
return cell.x >= 0 and cell.y >= 0 and cell.x < int(layout["width"]) and cell.y < int(layout["height"])
func _trace_beam() -> Array[int]:
var travelled: Array[int] = []
var cell := _to_cell(int(layout["source"]))
var heading: Vector2i = [NORTH, EAST, SOUTH, WEST][int(layout["direction"])]
for step in range(int(layout["width"]) * int(layout["height"]) * 4):
var spot := _to_index(cell)
travelled.append(spot)
if _can_turn(spot):
heading = _reflect(heading, _orientation_at(spot))
if layout["targets"].has(spot):
break
var next_cell := cell + heading
if not _inside(next_cell):
break
cell = next_cell
return travelled
func _reflect(heading: Vector2i, slant: int) -> Vector2i:
if slant == 0:
return Vector2i(-heading.y, -heading.x)
return Vector2i(heading.y, heading.x)
func _render() -> void:
active_path = _trace_beam()
won = active_path.has(int(layout["targets"][0]))
for index in range(tiles.size()):
var tile := tiles[index]
tile.text = _tile_label(index)
tile.modulate = Color("#9fece7") if active_path.has(index) else Color("#e8dcb9")
if won:
status.text = "%s complete!" % str(layout["name"])
else:
status.text = "%s · turn a mirror to guide the beam." % str(layout["name"])
func _tile_label(index: int) -> String:
if index == int(layout["source"]):
return "Lamp"
if layout["targets"].has(index):
return "Awake" if active_path.has(index) else "Goal"
if _can_turn(index):
var slash := "/" if _orientation_at(index) == 0 else "\\"
return slash
if active_path.has(index):
return "Beam"
return str(index)
func _add_action(row: HBoxContainer, caption: String, action: Callable) -> Button:
var button := Button.new()
button.text = caption
button.custom_minimum_size = Vector2(72, 36)
button.pressed.connect(action)
row.add_child(button)
return button
func _show_hint() -> void:
var turnables: Dictionary = layout["mirrors"]
var choices := turnables.keys()
if choices.is_empty():
status.text = "Follow the lamp beam in this room."
return
status.text = "Try one tile at a time. Mirror tile: %s." % str(choices[0])
func _reset() -> void:
rotations.clear()
_render()
func _show_help() -> void:
status.text = "Tap the mirror. A keyboard player can use Tab, then Enter."
func _next_room() -> void:
if not won:
status.text = "Wake the exhibits before visiting the next room."
return
_load_room((room_index + 1) % ROOMS.size())
func _load_room(index: int) -> void:
room_index = index
layout = ROOMS[index]
rotations.clear()
for old_tile in tiles:
grid.remove_child(old_tile)
old_tile.queue_free()
tiles.clear()
grid.columns = int(layout["width"])
_make_tiles()
_render()
func _can_turn(index: int) -> bool:
return layout["mirrors"].has(index)
func _orientation_at(index: int) -> int:
return int(rotations.get(index, layout["mirrors"].get(index, 0)))
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 ROOMS := [Creates a constant named ROOMS. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
{"name": "Ocean Gallery", "width": 5, "height": 5, "source": 10,Starts a list or dictionary used as part of the instruction above. -
"direction": 1, "mirrors": {12: 1}, "targets": [2]},Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
{"name": "Fossil Passage", "width": 5, "height": 5, "source": 10,Starts a list or dictionary used as part of the instruction above. -
"direction": 1, "mirrors": {12: 1, 7: 1}, "targets": [9]},Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
]Closes the parentheses, list or dictionary opened above. Any trailing comma separates this item from the next. -
const EAST := Vector2i(1, 0)Creates a constant named EAST. The expression packs whole-number x and y into one grid position. Godot infers the type from the first value. -
const SOUTH := Vector2i(0, 1)Creates a constant named SOUTH. The expression packs whole-number x and y into one grid position. Godot infers the type from the first value. -
const NORTH := Vector2i(0, -1)Creates a constant named NORTH. The expression packs whole-number x and y into one grid position. Godot infers the type from the first value. -
const WEST := Vector2i(-1, 0)Creates a constant named WEST. The expression packs whole-number x and y into one grid position. Godot infers the type from the first value. -
var grid: GridContainerDeclares grid for later use. A colon followed by a type says which kind of value belongs here. -
var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here. -
var tiles: Array[Button] = []Creates a variable named tiles. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var active_path: Array[int] = []Creates a variable named active_path. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var won := falseCreates a variable named won. The expression uses the yes-or-no value false. Godot infers the type from the first value. -
var room_index := 0Creates a variable named room_index. The expression uses the whole number 0. Godot infers the type from the first value. -
var layout: DictionaryDeclares layout for later use. A colon followed by a type says which kind of value belongs here. -
var rotations: Dictionary = {}Creates a variable named rotations. The expression makes a dictionary that looks up values by key. The type after the colon says what kind of value it can hold. -
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 background := ColorRect.new()Creates a variable named background. The expression creates a new ColorRect object. Godot infers the type from the first value. -
background.color = Color("#102a3b")Stores the new value in background.color. The expression builds a colour from these values. -
background.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates background.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
add_child(background)Adds the new node to the scene tree so that Godot can run and draw it. -
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Positions this Control relative to the bounds of its parent. -
var centre := CenterContainer.new()Creates a variable named centre. The expression creates a new CenterContainer object. Godot infers the type from the first value. -
add_child(centre)Adds the new node to the scene tree so that Godot can run and draw it. -
centre.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Positions this Control relative to the bounds of its parent. -
var page := VBoxContainer.new()Creates a variable named page. The expression creates a new VBoxContainer object. Godot infers the type from the first value. -
page.add_theme_constant_override("separation", 8)Calls page.add_theme_constant_override with the values in its parentheses. -
centre.add_child(page)Adds the new node to the scene tree so that Godot can run and draw it. -
var heading := Label.new()Creates a variable named heading. The expression creates a new Label object. Godot infers the type from the first value. -
heading.text = "Museum of Lost Lights"Updates heading.text, which controls the words a player sees. The expression uses the text inside the quotes. -
heading.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTERStores the new value in heading.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_CENTER. -
heading.add_theme_font_size_override("font_size", 26)Calls heading.add_theme_font_size_override with the values in its parentheses. -
page.add_child(heading)Adds the new node to the scene tree so that Godot can run and draw it. -
var subheading := Label.new()Creates a variable named subheading. The expression creates a new Label object. Godot infers the type from the first value. -
subheading.text = "Tap or keyboard-focus a mirror. Press the mirror to turn it."Updates subheading.text, which controls the words a player sees. The expression uses the text inside the quotes. -
subheading.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTERStores the new value in subheading.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_CENTER. -
page.add_child(subheading)Adds the new node to the scene tree so that Godot can run and draw it. -
grid = GridContainer.new()Stores the new value in grid. The expression creates a new GridContainer object. -
grid.columns = int(ROOMS[0]["width"])Stores the new value in grid.columns. The expression converts a suitable value to a whole number. -
grid.size_flags_horizontal = Control.SIZE_SHRINK_CENTERStores the new value in grid.size_flags_horizontal. The expression reads Control.SIZE_SHRINK_CENTER. -
page.add_child(grid)Adds the new node to the scene tree so that Godot can run and draw it. -
status = Label.new()Stores the new value in status. The expression creates a new Label object. -
status.custom_minimum_size.x = 460Stores the new value in status.custom_minimum_size.x. The expression uses the whole number 460. -
status.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTERStores the new value in status.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_CENTER. -
page.add_child(status)Adds the new node to the scene tree so that Godot can run and draw it. -
var actions := HBoxContainer.new()Creates a variable named actions. The expression creates a new HBoxContainer object. Godot infers the type from the first value. -
actions.alignment = BoxContainer.ALIGNMENT_CENTERUpdates actions.alignment, which controls how the control aligns its contents. The expression reads BoxContainer.ALIGNMENT_CENTER. -
page.add_child(actions)Adds the new node to the scene tree so that Godot can run and draw it. -
_add_action(actions, "Hint", _show_hint)Calls _add_action with the values in its parentheses. -
_add_action(actions, "Reset", _reset)Calls _add_action with the values in its parentheses. -
_add_action(actions, "Help", _show_help)Calls _add_action with the values in its parentheses. -
_add_action(actions, "Next room", _next_room)Calls _add_action with the values in its parentheses. -
_load_room(0)Calls _load_room with the values in its parentheses. -
func _make_tiles() -> void:Defines make tiles, 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. -
for index in range(int(layout["width"]) * int(layout["height"])):Repeats the indented instructions for each value in range(int(layout["width"]) * int(layout["height"])). -
var tile := Button.new()Creates a variable named tile. The expression creates a new Button object. Godot infers the type from the first value. -
tile.custom_minimum_size = Vector2(60, 48)Updates tile.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value. -
tile.focus_mode = Control.FOCUS_ALLStores the new value in tile.focus_mode. The expression reads Control.FOCUS_ALL. -
tile.pressed.connect(_tap_tile.bind(index))Links a signal to the function that should run when the event happens. -
tiles.append(tile)Adds an item to the end of a list. -
grid.add_child(tile)Adds the new node to the scene tree so that Godot can run and draw it. -
func _tap_tile(index: int) -> void:Defines tap tile, 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. -
if won or not _can_turn(index):Checks won or not _can_turn(index). The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var current := _orientation_at(index)Creates a variable named current. The expression calls _orientation_at with the values in its parentheses. Godot infers the type from the first value. -
rotations[index] = 1 - currentStores the new value in rotations[index]. The expression calculates a new value from the expressions on either side of the operator. -
_render()Calls _render with the values in its parentheses. -
func _to_index(cell: Vector2i) -> int:Defines to index, 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 cell.y * int(layout["width"]) + cell.xFinishes the function and hands its result back to the caller. The expression looks up the item or key written between the square brackets. -
func _to_cell(index: int) -> Vector2i:Defines to cell, 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. -
@warning_ignore("integer_division")This annotation gives Godot extra information about the declaration that follows. -
var row := index / int(layout["width"])Creates a variable named row. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value. -
return Vector2i(index % int(layout["width"]), row)Finishes the function and hands its result back to the caller. The expression packs whole-number x and y into one grid position. -
func _inside(cell: Vector2i) -> bool:Defines inside, 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 cell.x >= 0 and cell.y >= 0 and cell.x < int(layout["width"]) and cell.y < int(layout["height"])Finishes the function and hands its result back to the caller. The expression evaluates the test to see whether it is true or false. -
func _trace_beam() -> Array[int]:Defines trace beam, 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 travelled: Array[int] = []Creates a variable named travelled. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var cell := _to_cell(int(layout["source"]))Creates a variable named cell. The expression calls _to_cell with the values in its parentheses. Godot infers the type from the first value. -
var heading: Vector2i = [NORTH, EAST, SOUTH, WEST][int(layout["direction"])]Creates a variable named heading. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
for step in range(int(layout["width"]) * int(layout["height"]) * 4):Repeats the indented instructions for each value in range(int(layout["width"]) * int(layout["height"]) * 4). -
var spot := _to_index(cell)Creates a variable named spot. The expression calls _to_index with the values in its parentheses. Godot infers the type from the first value. -
travelled.append(spot)Adds an item to the end of a list. -
if _can_turn(spot):Checks _can_turn(spot). The indented instructions below run only if this test passes. -
heading = _reflect(heading, _orientation_at(spot))Stores the new value in heading. The expression calls _reflect with the values in its parentheses. -
if layout["targets"].has(spot):Checks layout["targets"].has(spot). The indented instructions below run only if this test passes. -
breakLeaves the loop immediately and continues with code after the loop. -
var next_cell := cell + headingCreates a variable named next_cell. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value. -
if not _inside(next_cell):Checks not _inside(next_cell). The indented instructions below run only if this test passes. -
breakLeaves the loop immediately and continues with code after the loop. -
cell = next_cellStores the new value in cell. The expression reads next_cell. -
return travelledFinishes the function and hands its result back to the caller. The expression reads travelled. -
func _reflect(heading: Vector2i, slant: int) -> Vector2i:Defines reflect, 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. -
if slant == 0:Checks slant == 0. The indented instructions below run only if this test passes. -
return Vector2i(-heading.y, -heading.x)Finishes the function and hands its result back to the caller. The expression packs whole-number x and y into one grid position. -
return Vector2i(heading.y, heading.x)Finishes the function and hands its result back to the caller. The expression packs whole-number x and y into one grid position. -
func _render() -> void:Defines render, 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. -
active_path = _trace_beam()Stores the new value in active_path. The expression calls _trace_beam with the values in its parentheses. -
won = active_path.has(int(layout["targets"][0]))Stores the new value in won. The expression asks whether the collection contains the value or key. -
for index in range(tiles.size()):Repeats the indented instructions for each value in range(tiles.size()). -
var tile := tiles[index]Creates a variable named tile. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value. -
tile.text = _tile_label(index)Updates tile.text, which controls the words a player sees. The expression calls _tile_label with the values in its parentheses. -
tile.modulate = Color("#9fece7") if active_path.has(index) else Color("#e8dcb9")Updates tile.modulate, which controls the colour and transparency used to tint this node and its children. The expression builds a colour from these values. -
if won:Checks won. The indented instructions below run only if this test passes. -
status.text = "%s complete!" % str(layout["name"])Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
status.text = "%s · turn a mirror to guide the beam." % str(layout["name"])Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes. -
func _tile_label(index: int) -> String:Defines tile label, 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. -
if index == int(layout["source"]):Checks index == int(layout["source"]). The indented instructions below run only if this test passes. -
return "Lamp"Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
if layout["targets"].has(index):Checks layout["targets"].has(index). The indented instructions below run only if this test passes. -
return "Awake" if active_path.has(index) else "Goal"Finishes the function and hands its result back to the caller. The expression chooses one of two values by checking the condition in the middle. -
if _can_turn(index):Checks _can_turn(index). The indented instructions below run only if this test passes. -
var slash := "/" if _orientation_at(index) == 0 else "\\"Creates a variable named slash. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
return slashFinishes the function and hands its result back to the caller. The expression reads slash. -
if active_path.has(index):Checks active_path.has(index). The indented instructions below run only if this test passes. -
return "Beam"Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
return str(index)Finishes the function and hands its result back to the caller. The expression turns a value into text for a player message. -
func _add_action(row: HBoxContainer, caption: String, action: Callable) -> Button:Defines add action, 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 button := Button.new()Creates a variable named button. The expression creates a new Button object. Godot infers the type from the first value. -
button.text = captionUpdates button.text, which controls the words a player sees. The expression reads caption. -
button.custom_minimum_size = Vector2(72, 36)Updates button.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value. -
button.pressed.connect(action)Links a signal to the function that should run when the event happens. -
row.add_child(button)Adds the new node to the scene tree so that Godot can run and draw it. -
return buttonFinishes the function and hands its result back to the caller. The expression reads button. -
func _show_hint() -> void:Defines show hint, 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 turnables: Dictionary = layout["mirrors"]Creates a variable named turnables. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var choices := turnables.keys()Creates a variable named choices. The expression calls turnables.keys with the values in its parentheses. Godot infers the type from the first value. -
if choices.is_empty():Checks choices.is_empty(). The indented instructions below run only if this test passes. -
status.text = "Follow the lamp beam in this room."Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
status.text = "Try one tile at a time. Mirror tile: %s." % str(choices[0])Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes. -
func _reset() -> void:Defines reset, 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. -
rotations.clear()Empties this collection. -
_render()Calls _render with the values in its parentheses. -
func _show_help() -> void:Defines show help, 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. -
status.text = "Tap the mirror. A keyboard player can use Tab, then Enter."Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes. -
func _next_room() -> void:Defines next room, 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. -
if not won:Checks not won. The indented instructions below run only if this test passes. -
status.text = "Wake the exhibits before visiting the next room."Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
_load_room((room_index + 1) % ROOMS.size())Calls _load_room with the values in its parentheses. -
func _load_room(index: int) -> void:Defines load room, 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. -
room_index = indexStores the new value in room_index. The expression reads index. -
layout = ROOMS[index]Stores the new value in layout. The expression looks up the item or key written between the square brackets. -
rotations.clear()Empties this collection. -
for old_tile in tiles:Repeats the indented instructions for each value in tiles. -
grid.remove_child(old_tile)Calls grid.remove_child with the values in its parentheses. -
old_tile.queue_free()Asks Godot to remove this node safely at the end of the frame. -
tiles.clear()Empties this collection. -
grid.columns = int(layout["width"])Stores the new value in grid.columns. The expression converts a suitable value to a whole number. -
_make_tiles()Calls _make_tiles with the values in its parentheses. -
_render()Calls _render with the values in its parentheses. -
func _can_turn(index: int) -> bool:Defines can turn, 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 layout["mirrors"].has(index)Finishes the function and hands its result back to the caller. The expression looks up the item or key written between the square brackets. -
func _orientation_at(index: int) -> int:Defines orientation at, 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 int(rotations.get(index, layout["mirrors"].get(index, 0)))Finishes the function and hands its result back to the caller. The expression converts a suitable value to a whole number.
Find and fix a bug
If the previous room’s turns carry over, check that _load_room clears rotations before rebuilding the grid. If the new board has extra tiles, check that old nodes are removed and the tiles array is cleared.
Try a change
On paper, design a two-mirror card with a different target. Stretch: change the starter values while keeping the room unsolved at first, and write the expected turn sequence.