Museum of Lost Lights · Lesson 37 of 50 · Advanced · About 36 min
A call arrives while a player turns a mirror. The museum should keep its progress and let the player decide when to continue.

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/36 when the lesson builds on prior work, or copy the checkpoints/37 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 Node._notification, if, and, set_pause, button.disabled, return.
-
Run the pause lab
Import and open this lesson's project. Press F5, then press Turn one mirror twice. Confirm the status shows two turns.
Why it works The turn count gives you a small fact you can watch to find unwanted moves.
-
Create one pause setting
In main.gd, inspect paused_for_player and set_pause. Press Pause visit and try the turn button. Then press Resume visit and turn again.
paused_for_player = should_pauseWhy it works The setting represents whether the game should accept puzzle input. set_pause takes the new Boolean and uses one line to redraw the controls.
-
Guard the game rule
At the start of turn_mirror, read the if and return lines. Notice they happen before turns += 1.
if paused_for_player: returnWhy it works Disabling a button helps players. The guard protects the rule itself even if input later comes from a keyboard shortcut or another script.
-
Respond to the app lifecycle
Read _notification. Find the constant for an application pause. Tap Simulate leaving the app on a computer, or switch away and back in a mobile build.
what == NOTIFICATION_APPLICATION_PAUSED and is_node_ready()Why it works Godot sends notifications to nodes when certain events happen. and asks for both the pause event and a ready scene, so the label already exists when animation-free state changes happen.
-
Stay paused until the player is ready
Note that the code has no automatic resume on the app returning. Press Resume visit when you want the next turn to count.
pause_button.text = "Resume visit" if paused_for_player else "Pause visit"Why it works Pressing resume is a deliberate player action. The counter and all other progress stay where you left them.
-
Follow the whole chain
Repeat the test starting at three turns. Before leaving, predict each state and compare. During playtesting, also check a real phone build for actual app switch behaviour.
Why it works A simulator button exercises the same pause rule. Only a device test can verify the phone's own notification and lifecycle behaviour.
Watch the values change
-
Turn mirror twice turns = 2 and active.
What you see. Status reads Exploring · 2 turns. -
Simulate leaving paused_for_player becomes true.
What you see. Turn is disabled and pause control changes to Resume visit. -
Resume and turn Guard allows a new move.
What you see. Status reads Exploring · 3 turns.
Predict before you run After two turns, leaving the app and returning, would a third turn count immediately?
Reveal the answer
No. Application pause makes the game stay paused. The next turn counts only after the player presses Resume.
Complete checkpoint
A simulated leave keeps the turn count, blocks puzzle input and waits for Resume. The mobile build can exercise the OS notification once exported.
main.gd
extends Control
var paused_for_player := false
var turns := 0
var readout: Label
var turn_button: Button
var pause_button: Button
func _ready() -> void:
var panel := make_panel("37 · Pause and resume safely")
readout = make_label(panel, "")
turn_button = make_button(panel, "Turn one mirror", turn_mirror)
pause_button = make_button(panel, "Pause visit", toggle_pause)
make_button(panel, "Simulate leaving the app", func(): set_pause(true))
show_status()
func _notification(what: int) -> void:
if what == NOTIFICATION_APPLICATION_PAUSED and is_node_ready():
set_pause(true)
func toggle_pause() -> void:
set_pause(not paused_for_player)
func set_pause(should_pause: bool) -> void:
paused_for_player = should_pause
show_status()
func turn_mirror() -> void:
if paused_for_player:
return
turns += 1
show_status()
func show_status() -> void:
var label := "Paused · ready when you are" if paused_for_player else "Exploring"
readout.text = "%s · %d turns" % [label, turns]
turn_button.disabled = paused_for_player
pause_button.text = "Resume visit" if paused_for_player else "Pause visit"
func make_panel(heading: String, width: float = 580.0) -> VBoxContainer:
var margin := MarginContainer.new()
margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
for side in ["left", "right", "top", "bottom"]:
margin.add_theme_constant_override("margin_" + side, 24)
add_child(margin)
var centring := CenterContainer.new()
margin.add_child(centring)
var panel := VBoxContainer.new()
panel.custom_minimum_size.x = width
panel.add_theme_constant_override("separation", 12)
centring.add_child(panel)
make_label(panel, heading, 28)
return panel
func make_label(parent: Control, message: String, size: int = 18) -> Label:
var label := Label.new()
label.text = message
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
label.add_theme_font_size_override("font_size", size)
parent.add_child(label)
return label
func make_button(parent: Control, caption: String, handle_press: Callable) -> Button:
var button := Button.new()
button.text = caption
button.custom_minimum_size.y = 52
button.pressed.connect(handle_press)
parent.add_child(button)
return button
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 ControlGive this script the layout and input abilities of Godot's Control node. The code below turns the root Control into a particular museum practice scene. -
var paused_for_player := falseCreates a variable named paused_for_player. The expression uses the yes-or-no value false. Godot infers the type from the first value. -
var turns := 0Creates a variable named turns. The expression uses the whole number 0. Godot infers the type from the first value. -
var readout: LabelDeclares readout for later use. A colon followed by a type says which kind of value belongs here. -
var turn_button: ButtonDeclares turn_button for later use. A colon followed by a type says which kind of value belongs here. -
var pause_button: ButtonDeclares pause_button for later use. A colon followed by a type says which kind of value belongs here. -
func _ready() -> void:Godot calls this function once when the node is ready. The indented setup creates the interface and gives its controls their starting values. -
var panel := make_panel("37 · Pause and resume safely")Creates a variable named panel. The expression calls make_panel with the values in its parentheses. Godot infers the type from the first value. -
readout = make_label(panel, "")Stores the new value in readout. The expression calls make_label with the values in its parentheses. -
turn_button = make_button(panel, "Turn one mirror", turn_mirror)Stores the new value in turn_button. The expression calls make_button with the values in its parentheses. -
pause_button = make_button(panel, "Pause visit", toggle_pause)Stores the new value in pause_button. The expression calls make_button with the values in its parentheses. -
make_button(panel, "Simulate leaving the app", func(): set_pause(true))Calls make_button with the values in its parentheses. -
show_status()Calls show_status with the values in its parentheses. -
func _notification(what: int) -> void:Godot calls this function when sending a numbered engine notification to this node. -
if what == NOTIFICATION_APPLICATION_PAUSED and is_node_ready():Only react to a system pause and only after the scene's interface has been set up. -
set_pause(true)Calls set_pause with the values in its parentheses. -
func toggle_pause() -> void:Defines toggle pause, 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. -
set_pause(not paused_for_player)Calls set_pause with the values in its parentheses. -
func set_pause(should_pause: bool) -> void:Defines set pause, 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. -
paused_for_player = should_pauseCopy the requested pause state into the main game variable so every check reads the same answer. -
show_status()Calls show_status with the values in its parentheses. -
func turn_mirror() -> void:Defines turn mirror, 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 paused_for_player:Check whether the player is paused. If so, leave the move function before counting anything. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
turns += 1Add exactly one to the count of accepted mirror turns and keep that result as the current count. -
show_status()Calls show_status with the values in its parentheses. -
func show_status() -> void:Defines show status, 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 label := "Paused · ready when you are" if paused_for_player else "Exploring"Creates a variable named label. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
readout.text = "%s · %d turns" % [label, turns]Updates readout.text, which controls the words a player sees. The expression uses the text inside the quotes. -
turn_button.disabled = paused_for_playerMake the turning control unavailable while paused, and return it when the player resumes. -
pause_button.text = "Resume visit" if paused_for_player else "Pause visit"Name the action the pause button will take in the current state. -
func make_panel(heading: String, width: float = 580.0) -> VBoxContainer:Make a helper that takes the heading text and the panel's minimum width. If the caller omits the width, use 580 game pixels. Return the laid-out panel so the caller can add more controls. -
var margin := MarginContainer.new()Create a container that can reserve clear space between the game controls and the window edges. -
margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Choose the preset that aligns the margin's edges with all four edges of the parent Control. -
for side in ["left", "right", "top", "bottom"]:Visit the four names in order so the following indented line can set one margin on each trip through the loop. -
margin.add_theme_constant_override("margin_" + side, 24)Join margin_ to the current side's name. Set that edge to 24 game pixels, and repeat for the other sides. -
add_child(margin)Connect the completed margin container to the lesson's scene root so it can lay out its children. -
var centring := CenterContainer.new()Make a container that will centre the controls within the available space. -
margin.add_child(centring)Give the centring container the space inside the extra border, then let it place the panel within that space. -
var panel := VBoxContainer.new()Create a container that arranges its child controls in one vertical column. -
panel.custom_minimum_size.x = widthAsk the layout for at least the selected width, where x is the horizontal part of the size. -
panel.add_theme_constant_override("separation", 12)Leave 12 game pixels of space between each pair of controls in the vertical panel. -
centring.add_child(panel)Attach the vertical column to the centring container. Godot can now place the whole column together. -
make_label(panel, heading, 28)Put the supplied heading at the top of the column and ask for a larger 28-pixel font. -
return panelHand the panel reference back to the caller so it can add labels or buttons under the heading. -
func make_label(parent: Control, message: String, size: int = 18) -> Label:Accept the parent control, text to show and optional font size. Return the new Label so the caller can update it later. -
var label := Label.new()Make a new empty Label, which is Godot's text display node. -
label.text = messageCopy the incoming message into the label's visible words. -
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTLet the label wrap lines at sensible places so a long message can fit when the layout is narrow. -
label.add_theme_font_size_override("font_size", size)Set the chosen size on this one label so other text can keep different sizes. -
parent.add_child(label)Add the label to the supplied parent. It becomes part of that panel's layout and can appear on screen. -
return labelReturn the exact label you created so the caller can change its text without building a second label. -
func make_button(parent: Control, caption: String, handle_press: Callable) -> Button:Build and return one Button. The arguments identify its parent, the words on it and the action to run after pressing it. -
var button := Button.new()Create a Godot Button that supports pointer, touch and keyboard activation. -
button.text = captionPut the supplied caption on the visible control. -
button.custom_minimum_size.y = 52Reserve at least 52 game pixels vertically so the control remains a comfortable target. -
button.pressed.connect(handle_press)Connect the pressed signal to the supplied callable. Godot waits for activation before running the action. -
parent.add_child(button)Attach the Button to its parent and let that container position it. -
return buttonGive the finished Button to the caller, which can keep a reference to set focus or change the caption later.
Find and fix a bug
If a keyboard shortcut can still turn a mirror while paused, route it through turn_mirror rather than changing turns directly.
Try a change
Ages 10–12 can change the paused status and test whether a tester understands how to resume. Ages 13–16 can link the same state to pause and unpause an optional animation.