Tiny Shelf Studio · Lesson 39 of 50 · Intermediate to advanced · About 35 min
The scrapbook is a record of displays built. A three-card rehearsal makes it easy to trace how a finish opens the next door before the finished game expands to nine briefs.

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/38 when the lesson builds on prior work, or copy the checkpoints/39 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 Array, Dictionary, Button.disabled, maxi, mini, String.
-
Open the design bench
Import this checkpoint's project.godot into Godot 4.7.2. Open main.gd from FileSystem. Press F5 for the starting view and F8 to stop it. Keep a copy to undo experiments.
Why it works The checkpoint scene attaches main.gd to a Control. Each test starts from that known version, so compare one change with the original.
-
Read the three brief records
Find the ID and title in BRIEFS. Rename Window Crew, then run the checkpoint and see the card text change.
const BRIEFS := [Why it works The title is for readers. The same ID remains the key used to award that stamp.
-
Disable cards after the last open brief
Start practice again. See that only the first card can be clicked. Follow the Boolean expression that disables the other two.
cards[i].disabled = i > openedWhy it works The highest open index is zero at the start. Every larger index is locked.
-
Keep a rule guard below the buttons
Read choose. Temporarily call choose(2) from the bottom of _ready and verify the first display is still current.
if index < 0 or index > opened:Why it works A visible lock explains availability. The guard also blocks any invalid choice sent by another control or a test.
-
Write one stamp and one unlock
Select First Display and use Finish display twice. Check that the count stays one and that only Rainbow Row opens.
opened = maxi(opened, mini(current + 1, BRIEFS.size() - 1))Why it works A dictionary key is unique. mini stops at the last brief, and maxi keeps older completed cards from closing later ones.
-
Verify the final unlock
Finish both remaining briefs. Press Finish display on the last one and switch back to First Display. Check that all three stay playable.
stamps[brief["id"]] = trueWhy it works The last index stays inside the list whether the final display finishes once or twice.
Watch the values change
-
Reset opened is 0 and stamps is empty.
What you see. Only First Display can be chosen. -
Finish first display twice stamps contains a single ID and opened is 1.
What you see. Rainbow Row is ready and Window Crew stays locked. -
Finish the other two opened is capped at 2 and stamps.size() is 3.
What you see. All three cards can be revisited.
Predict before you run Does finishing First Display again after opening Window Crew re-lock the last card?
Reveal the answer
No. maxi compares the old highest open index with the next index after First Display and keeps the larger value.
Complete checkpoint
A three-brief practice board showing readable locks and one scrapbook stamp per finished brief.
main.gd
extends Control
const BRIEFS := [
{"id": "first_display", "title": "First Display"},
{"id": "rainbow_row", "title": "Rainbow Row"},
{"id": "window_crew", "title": "Window Crew"},
]
var opened := 0
var current := 0
var stamps: Dictionary = {}
var cards: Array[Button] = []
var result: Label
var count: Label
func _ready() -> void:
title_page("BRIEFS", "Unlock briefs in order", "Finish a display to add its stamp and open the next challenge.")
for i in range(BRIEFS.size()):
cards.append(place_button("", Vector2(54 + 293 * i, 232), choose.bind(i), 270))
result = label("", Vector2(54, 312), 22, SEA)
count = label("", Vector2(55, 349), 17, GOLD)
place_button("Finish display", Vector2(55, 413), complete)
place_button("Start practice again", Vector2(249, 413), restart, 215)
refresh()
func choose(index: int) -> void:
if index < 0 or index > opened:
return
current = index
refresh()
func complete() -> void:
var brief: Dictionary = BRIEFS[current]
stamps[brief["id"]] = true
opened = maxi(opened, mini(current + 1, BRIEFS.size() - 1))
refresh()
func restart() -> void:
opened = 0
current = 0
stamps.clear()
refresh()
func refresh() -> void:
for i in range(cards.size()):
var brief: Dictionary = BRIEFS[i]
var marker := "Locked · " if i > opened else "Ready · "
if stamps.has(brief["id"]):
marker = "✓ "
cards[i].text = marker + str(brief["title"])
cards[i].disabled = i > opened
result.text = "Current display · " + str(BRIEFS[current]["title"])
count.text = "Scrapbook stamps · %d / %d" % [stamps.size(), BRIEFS.size()]
func _draw() -> void:
backdrop()
panel(Rect2(44, 179, 875, 206), Color("#244457"), EDGE)
const PAPER := Color("#fff4de")
const GOLD := Color("#f5bd79")
const SEA := Color("#9ddcd0")
const INK := Color("#172c3c")
const EDGE := Color("#54817f")
func title_page(unit: String, heading: String, subtitle: String) -> void:
label("TINY SHELF STUDIO / " + unit, Vector2(44, 36), 14, GOLD)
label(heading, Vector2(44, 65), 33)
label(subtitle, Vector2(46, 119), 16, SEA)
func label(words: String, at: Vector2, pixels: int = 20, ink: Color = PAPER) -> Label:
var item := Label.new()
item.text = words
item.position = at
item.add_theme_font_size_override("font_size", pixels)
item.add_theme_color_override("font_color", ink)
add_child(item)
return item
func place_button(words: String, at: Vector2, action: Callable, width: float = 170.0) -> Button:
var control := Button.new()
control.text = words
control.position = at
control.custom_minimum_size = Vector2(width, 48)
control.add_theme_font_size_override("font_size", 17)
control.add_theme_color_override("font_color", PAPER)
control.add_theme_stylebox_override("normal", style(Color("#244557"), EDGE))
control.add_theme_stylebox_override("hover", style(Color("#365a62"), SEA))
control.add_theme_stylebox_override("pressed", style(Color("#315b56"), SEA))
control.add_theme_stylebox_override("focus", style(Color.TRANSPARENT, GOLD, 3))
control.pressed.connect(action)
add_child(control)
return control
func style(fill: Color, edge: Color, line: int = 1) -> StyleBoxFlat:
var block := StyleBoxFlat.new()
block.bg_color = fill
block.border_color = edge
block.set_border_width_all(line)
block.set_corner_radius_all(8)
return block
func panel(rect: Rect2, fill: Color, edge: Color = EDGE) -> void:
draw_style_box(style(fill, edge), rect)
func backdrop() -> void:
draw_rect(Rect2(Vector2.ZERO, size), Color("#102333"))
panel(Rect2(22, 19, size.x - 44, size.y - 38), Color("#183344"), Color("#325665"))
func paint_words(words: String, at: Vector2, pixels: int = 16, ink: Color = PAPER) -> void:
draw_string(ThemeDB.fallback_font, at, words, HORIZONTAL_ALIGNMENT_LEFT, -1, pixels, ink)
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 BRIEFS := [The array order defines the story sequence. The first three are simplified examples for this checkpoint. -
{"id": "first_display", "title": "First Display"},Starts a list or dictionary used as part of the instruction above. -
{"id": "rainbow_row", "title": "Rainbow Row"},Starts a list or dictionary used as part of the instruction above. -
{"id": "window_crew", "title": "Window Crew"},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 opened := 0Store the farthest unlocked index. The first card opens at zero. -
var current := 0Creates a variable named current. The expression uses the whole number 0. Godot infers the type from the first value. -
var stamps: Dictionary = {}Use unique keys for earned stamps, avoiding extra copies when a player replays a display. -
var cards: Array[Button] = []Creates a variable named cards. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var result: LabelDeclares result for later use. A colon followed by a type says which kind of value belongs here. -
var count: LabelDeclares count 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. -
title_page("BRIEFS", "Unlock briefs in order", "Finish a display to add its stamp and open the next challenge.")Calls title_page with the values in its parentheses. -
for i in range(BRIEFS.size()):Repeats the indented instructions for each value in range(BRIEFS.size()). -
cards.append(place_button("", Vector2(54 + 293 * i, 232), choose.bind(i), 270))Adds an item to the end of a list. -
result = label("", Vector2(54, 312), 22, SEA)Stores the new value in result. The expression calls label with the values in its parentheses. -
count = label("", Vector2(55, 349), 17, GOLD)Stores the new value in count. The expression calls label with the values in its parentheses. -
place_button("Finish display", Vector2(55, 413), complete)Calls place_button with the values in its parentheses. -
place_button("Start practice again", Vector2(249, 413), restart, 215)Calls place_button with the values in its parentheses. -
refresh()Calls refresh with the values in its parentheses. -
func choose(index: int) -> void:Defines choose, 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 < 0 or index > opened:Refuse an unavailable choice before storing it as the current brief. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
current = indexStores the new value in current. The expression reads index. -
refresh()Calls refresh with the values in its parentheses. -
func complete() -> void:Defines complete, 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 brief: Dictionary = BRIEFS[current]Read whichever brief the player is completing, including a replayed one. -
stamps[brief["id"]] = trueAward the current brief's stamp exactly once by using its key. -
opened = maxi(opened, mini(current + 1, BRIEFS.size() - 1))Keep past unlocks and cap the next index at the final brief. -
refresh()Calls refresh with the values in its parentheses. -
func restart() -> void:Defines restart, 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. -
opened = 0Stores the new value in opened. The expression uses the whole number 0. -
current = 0Stores the new value in current. The expression uses the whole number 0. -
stamps.clear()Clear the in-memory practice state. This app never touches the permanent reference scrapbook. -
refresh()Calls refresh with the values in its parentheses. -
func refresh() -> void:Defines refresh, 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 i in range(cards.size()):Repeats the indented instructions for each value in range(cards.size()). -
var brief: Dictionary = BRIEFS[i]Creates a variable named brief. 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 marker := "Locked · " if i > opened else "Ready · "Put the lock state in text so the button still tells players why it is dimmed. -
if stamps.has(brief["id"]):Checks stamps.has(brief["id"]). The indented instructions below run only if this test passes. -
marker = "✓ "Stores the new value in marker. The expression uses the text inside the quotes. -
cards[i].text = marker + str(brief["title"])Updates cards[i].text, which controls the words a player sees. The expression looks up the item or key written between the square brackets. -
cards[i].disabled = i > openedKeep locked controls from emitting a normal press. -
result.text = "Current display · " + str(BRIEFS[current]["title"])Updates result.text, which controls the words a player sees. The expression uses the text inside the quotes. -
count.text = "Scrapbook stamps · %d / %d" % [stamps.size(), BRIEFS.size()]Read the number of unique keys and the full brief count for the status panel. -
func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state. -
backdrop()Calls backdrop with the values in its parentheses. -
panel(Rect2(44, 179, 875, 206), Color("#244457"), EDGE)Calls panel with the values in its parentheses. -
const PAPER := Color("#fff4de")Creates a constant named PAPER. The expression builds a colour from these values. Godot infers the type from the first value. -
const GOLD := Color("#f5bd79")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value. -
const SEA := Color("#9ddcd0")Creates a constant named SEA. The expression builds a colour from these values. Godot infers the type from the first value. -
const INK := Color("#172c3c")Creates a constant named INK. The expression builds a colour from these values. Godot infers the type from the first value. -
const EDGE := Color("#54817f")Creates a constant named EDGE. The expression builds a colour from these values. Godot infers the type from the first value. -
func title_page(unit: String, heading: String, subtitle: String) -> void:Defines title page, 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. -
label("TINY SHELF STUDIO / " + unit, Vector2(44, 36), 14, GOLD)Make a small line above the main heading so you can tell which checkpoint is open. -
label(heading, Vector2(44, 65), 33)Calls label with the values in its parentheses. -
label(subtitle, Vector2(46, 119), 16, SEA)Calls label with the values in its parentheses. -
func label(words: String, at: Vector2, pixels: int = 20, ink: Color = PAPER) -> Label:Defines 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. -
var item := Label.new()Creates a variable named item. The expression creates a new Label object. Godot infers the type from the first value. -
item.text = wordsUpdates item.text, which controls the words a player sees. The expression reads words. -
item.position = atUpdates item.position, which controls the node's local x and y location. The expression reads at. -
item.add_theme_font_size_override("font_size", pixels)This Label has its own readable type size. Changing that value leaves the other labels alone. -
item.add_theme_color_override("font_color", ink)This label keeps the chosen text ink even when the default theme changes. -
add_child(item)Adds the new node to the scene tree so that Godot can run and draw it. -
return itemFinishes the function and hands its result back to the caller. The expression reads item. -
func place_button(words: String, at: Vector2, action: Callable, width: float = 170.0) -> Button:Defines place 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 = wordsUpdates control.text, which controls the words a player sees. The expression reads words. -
control.position = atUpdates control.position, which controls the node's local x and y location. The expression reads at. -
control.custom_minimum_size = Vector2(width, 48)Give the button room for its label and an easy target for taps. Containers and layouts can allocate more space. -
control.add_theme_font_size_override("font_size", 17)Calls control.add_theme_font_size_override with the values in its parentheses. -
control.add_theme_color_override("font_color", PAPER)Calls control.add_theme_color_override with the values in its parentheses. -
control.add_theme_stylebox_override("normal", style(Color("#244557"), EDGE))Calls control.add_theme_stylebox_override with the values in its parentheses. -
control.add_theme_stylebox_override("hover", style(Color("#365a62"), SEA))Calls control.add_theme_stylebox_override with the values in its parentheses. -
control.add_theme_stylebox_override("pressed", style(Color("#315b56"), SEA))Calls control.add_theme_stylebox_override with the values in its parentheses. -
control.add_theme_stylebox_override("focus", style(Color.TRANSPARENT, GOLD, 3))Draw a gold outline around keyboard focus. Other button styles can still indicate hover and press independently. -
control.pressed.connect(action)pressed fires on a successful control activation. Godot calls the function passed in without running it at setup time. -
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. -
func style(fill: Color, edge: Color, line: int = 1) -> StyleBoxFlat:Defines style, 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 block := StyleBoxFlat.new()Creates a variable named block. The expression creates a new StyleBoxFlat object. Godot infers the type from the first value. -
block.bg_color = fillStores the new value in block.bg_color. The expression reads fill. -
block.border_color = edgeStores the new value in block.border_color. The expression reads edge. -
block.set_border_width_all(line)Apply one border line width to all four edges of the card. -
block.set_corner_radius_all(8)Round each corner of this reusable style by eight pixels. -
return blockFinishes the function and hands its result back to the caller. The expression reads block. -
func panel(rect: Rect2, fill: Color, edge: Color = EDGE) -> void:Defines panel, 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. -
draw_style_box(style(fill, edge), rect)Calls draw_style_box with the values in its parentheses. -
func backdrop() -> void:Defines backdrop, 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. -
draw_rect(Rect2(Vector2.ZERO, size), Color("#102333"))Paints a rectangle at the given position and size. -
panel(Rect2(22, 19, size.x - 44, size.y - 38), Color("#183344"), Color("#325665"))Subtract space on both sides of the canvas. As the window changes, the outer frame fits within it. -
func paint_words(words: String, at: Vector2, pixels: int = 16, ink: Color = PAPER) -> void:Defines paint words, 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. -
draw_string(ThemeDB.fallback_font, at, words, HORIZONTAL_ALIGNMENT_LEFT, -1, pixels, ink)Godot draws the words from the baseline at the supplied pixel position using its fallback typeface.
Find and fix a bug
If replay adds extra stamps, check whether you are appending to an array each time. Use the unique brief ID as a key.
Try a change
Add a fourth brief and move the card list into a two-row grid. Test completing and replaying after the fourth card opens.