Museum of Lost Lights · Lesson 05 of 50 · Beginner · About 35 min
The first visitor’s task is to wake an exhibit. Give the night crew a switch that remembers every time it has worked.

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/04 when the lesson builds on prior work, or copy the checkpoints/05 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 Button, pressed, Signal.connect, Callable, +=, state, render.
-
Identify the value and the sign
Import Lesson 05, open main.tscn and read the two variables at the top of main.gd. Locate the assignments to readout inside _ready.
var awakened: int = 0 var readout: LabelWhy it works awakened is the game’s state, a value that remembers what has happened. readout has type Label. The script fills this variable with a new Label before the game can use it.
-
Give the visitor a switch
Find where the button is made, named and positioned. Run the scene and compare the button’s minimum size with the title above it.
switch_button.custom_minimum_size = Vector2(250, 64)Why it works Button.new creates a Control node capable of receiving input. custom_minimum_size reserves at least the width and height you set. A larger area is easier to tap.
-
Connect the notification
Read the pressed.connect line. Notice that the function name inside the outside pair of parentheses has no () of its own.
switch_button.pressed.connect(_on_wake_pressed)Why it works pressed is a signal, a notice the button sends at activation. connect gives the signal a callable function to run later. Putting empty parentheses after its name would call the function straight away.
-
Change the count and refresh
Trace the two lines in _on_wake_pressed. Run and click twice, watching the text each time.
awakened += 1 refresh_readout()Why it works += 1 is short for setting a variable to its previous value plus one. refresh_readout puts the newly changed value into the Label.
-
Find the first value on screen
Restart the scene and read the counter before pressing anything. Find the last instruction in _ready that makes this starting value appear.
readout.text = "Exhibits awakened: " + str(awakened)Why it works The first refresh paints the starting state. Later refreshes paint whatever the signal handler changed.
Watch the values change
-
Run the scene awakened starts at 0
What you see. The first refresh shows 0. -
Activate the button once pressed calls the handler and awakened += 1
What you see. The second refresh shows 1. -
Activate it again awakened changes from 1 to 2
What you see. The third refresh shows 2. -
Restart the scene A new script instance starts at 0
What you see. The exhibit counter is fresh.
Predict before you run What would happen if you removed just the refresh_readout() line from the button handler?
Reveal the answer
The number kept in awakened would still increase. The visible Label would keep showing its old text because the handler did not redraw it.
Complete checkpoint
The panel starts at Exhibits awakened: 0. Every click or tap on Wake an exhibit adds one.
main.gd
extends Control
var awakened: int = 0
var readout: Label
func _ready() -> void:
make_heading()
readout = Label.new()
readout.position = Vector2(54, 114)
readout.add_theme_font_size_override("font_size", 27)
add_child(readout)
var switch_button := Button.new()
switch_button.text = "Wake an exhibit"
switch_button.position = Vector2(54, 182)
switch_button.custom_minimum_size = Vector2(250, 64)
switch_button.add_theme_font_size_override("font_size", 24)
switch_button.pressed.connect(_on_wake_pressed)
add_child(switch_button)
refresh_readout()
func _on_wake_pressed() -> void:
awakened += 1
refresh_readout()
func refresh_readout() -> void:
readout.text = "Exhibits awakened: " + str(awakened)
func make_heading() -> void:
var heading := Label.new()
heading.text = "Night shift · Exhibit switch"
heading.position = Vector2(52, 36)
heading.add_theme_font_size_override("font_size", 38)
heading.add_theme_color_override("font_color", Color("#ffe1a8"))
add_child(heading)
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 ControlThe scene root behaves like a Control, the kind of Godot node used for a game’s text, controls and other interface pieces. -
var awakened: int = 0Remember how many times the player has awakened an exhibit. This starts at zero in a fresh run. -
var readout: LabelReserve a name for a Label node. The setup function puts the real Label there before the game first displays it. -
func _ready() -> void:Godot automatically calls this setup function after bringing this node and its children into the scene. The code below it prepares the first frame. -
make_heading()Build the title before the room makes its other controls. -
readout = Label.new()Create the Label now. Its stored reference lets later signal handlers change the same sign. -
readout.position = Vector2(54, 114)Use two numbers to give this control its position, measured right and down from the root. -
readout.add_theme_font_size_override("font_size", 27)Set a larger or smaller font here without changing the typography on the other controls. -
add_child(readout)Put the stored Label on the visible scene. Changes to its text now show on screen. -
var switch_button := Button.new()Create the button that lets players wake an exhibit. -
switch_button.text = "Wake an exhibit"Put the action in words directly on the button. -
switch_button.position = Vector2(54, 182)Use two numbers to give this control its position, measured right and down from the root. -
switch_button.custom_minimum_size = Vector2(250, 64)Give the button at least this much width and height so it is easy to hit with a mouse or finger. -
switch_button.add_theme_font_size_override("font_size", 24)Set a larger or smaller font here without changing the typography on the other controls. -
switch_button.pressed.connect(_on_wake_pressed)Connect the button’s pressed notice to a callable function. Giving its name without parentheses lets Godot call it only when the player activates the button. -
add_child(switch_button)Add the button to the scene so visitors can see and use it. -
refresh_readout()Show the initial count of zero before any button action is received. -
func _on_wake_pressed() -> void:Start the signal handler that runs on every accepted button activation. -
awakened += 1Take the previous count, add one and store it back in awakened. -
refresh_readout()Update the text after changing the count. This order means the player sees the new count right away. -
func refresh_readout() -> void:Keep the code that changes the on-screen words together so both setup and player actions can call it. -
readout.text = "Exhibits awakened: " + str(awakened)Convert the stored number to a String and join it to the fixed description. -
func make_heading() -> void:Group the instructions that make the panel title. The room calls this once at startup. -
var heading := Label.new()Create a Label node and keep a reference under the name heading so the next lines all customise the same sign. -
heading.text = "Night shift · Exhibit switch"Show the name of this museum task above its controls. -
heading.position = Vector2(52, 36)Put the title 52 pixels to the right and 36 pixels down from the root’s upper-left corner. -
heading.add_theme_font_size_override("font_size", 38)Set this heading’s font size to 38. The other labels keep their own sizes. -
heading.add_theme_color_override("font_color", Color("#ffe1a8"))Give only this label a warm gold text colour. The six characters after # describe red, green and blue light. -
add_child(heading)Connect the title to the scene tree so Godot can display it.
Find and fix a bug
If pressing the button changes nothing, search for pressed.connect. Pass _on_wake_pressed with its exact spelling and no parentheses after its name. If the debugger says readout is null, make sure refresh_readout runs after readout = Label.new().
Try a change
Ages 10–12: Change the button’s words and count three taps. Ages 13–16: Add a second button with its own handler that resets awakened to zero and calls refresh_readout.