Tiny Shelf Studio · Lesson 41 of 50 · Publishing · About 45 min
A collector has a three-slot window for Lemon Fizz, Moon Milk and Jam Toast. Lemon Fizz has one fixed shelf slot. Your task is to plan and verify the rest of the brief.

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/40 when the lesson builds on prior work, or copy the checkpoints/41 folder to try this lesson on its own. Read the file names in the steps before editing. Keep the checkpoint ZIP intact and make edits in an extracted working copy.


Build it step by step
Language and tools in this lesson Array[String], Vector2i, %, absolute values, recursive search, witness.
-
Plan the pack
Sketch a miniature pack for an invented product. Label the front, side and top. Give it a short name, an original symbol and a category. Draw the shelf positions 0, 1 and 4 on a 4 × 3 grid.
Why it works The 4 × 3 shelf counts across from zero. The second row begins at 4, directly below slot 0.
-
Run both tests
Import checkpoint 41, open main.gd, press F5, then try Test both neighbours and Test a conflicting brief. Predict the difference before reading the result.
Why it works Both cases start with the same three minis. The failing one requires Jam Toast to be diagonal from Lemon Fizz and next to it at the same time.
-
Find which cells touch
Trace adjacent(). Work out the column and row for slots 1 and 4. Add the horizontal and vertical distances. Then compare slots 0 and 4.
return distance.x + distance.y == 1Why it works A horizontal or vertical neighbour has distance 1. A diagonal changes both axes, giving distance 2.
-
Try each unused item
Read search(). Its loop picks a mini, duplicates the unused list, takes that mini out of the new list, and searches the next slot. Read the next line that removes the trial placement.
placed.erase(slot)Why it works Copying isolates the items you can still use inside that trial. Removing the placement gives the next choice a clean shelf.
-
Count actual solutions
Read valid() and the return at the start of search(). Confirm that Lemon Fizz is in slot 0, then try to put Jam Toast either right or below. Use the reported count to check your drawing.
return 1 if valid(placed, conflicting) else 0Why it works Each complete layout has one result. A count of two supplies two distinct possible solutions.
-
Create a new brief
Copy the editable game. Use a record in levels/briefs.json as a model. Make a fresh id and title, edit active and stock, then set at least two conditions in fixed, rows or pairs. Preserve the example record structure. Use the in-game hint and finish it without the hint on a fresh run. Record one winning layout for your test notes.
Why it works A working answer is an example that proves your challenge can be solved. Test the original build as well as this smaller checkpoint.
Watch the values change
-
Try an open brief Lemon Fizz occupies 0. Both 1 and 4 share an edge with 0.
What you see. One or the other can hold Jam Toast. -
Count every full layout Only unused items enter each next slot.
What you see. Two display layouts satisfy the rules. -
Require Jam Toast to be diagonal A diagonal is two changes away.
What you see. No arrangement meets both requirements.
Predict before you run Do slots 1 and 4 touch along an edge?
Reveal the answer
Slot 1 is column 1, row 0. Slot 4 is column 0, row 1. Their total distance is 2, so they are diagonal.
Complete checkpoint
The edge-neighbour brief reports two layouts. Combining the edge rule with a diagonal requirement reports zero.
main.gd
extends Control
const Lab = preload("res://release_lab.gd")
const PackArt = preload("res://pack_preview.gd")
const TITLE := "Design and validate an original display"
const NUMBER := 41
var ui: VBoxContainer
func _ready() -> void:
var preview := Control.new()
preview.set_script(PackArt)
preview.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(preview)
preview.set_anchors_and_offsets_preset(Control.PRESET_RIGHT_WIDE)
preview.offset_left = -258.0
preview.offset_right = -28.0
preview.offset_top = 32.0
preview.offset_bottom = -32.0
ui = VBoxContainer.new()
ui.set_script(Lab)
add_child(ui)
ui.start(TITLE, NUMBER)
build()
const WIDTH := 4
const ACTIVE: Array[int] = [0, 1, 4]
const STOCK: Array[String] = ["lemon_fizz", "moon_milk", "jam_toast"]
func build() -> void:
ui.say("Three minis, three slots. Find out which window rules have a solution.")
ui.option("Test both neighbours", report.bind(false))
ui.option("Test a conflicting brief", report.bind(true))
func report(conflicting: bool) -> void:
var total := search(0, {}, STOCK, conflicting)
if total == 0:
ui.say("0 valid layouts. The diagonal rule conflicts with the edge rule.")
else:
ui.say("%d valid layouts. Jam Toast can go beside or beneath Lemon Fizz." % total)
func adjacent(first: int, second: int) -> bool:
var a := Vector2i(first % WIDTH, floori(float(first) / WIDTH))
var b := Vector2i(second % WIDTH, floori(float(second) / WIDTH))
var distance := (a - b).abs()
return distance.x + distance.y == 1
func search(index: int, placed: Dictionary, unused: Array[String], conflicting: bool) -> int:
if index == ACTIVE.size():
return 1 if valid(placed, conflicting) else 0
var total := 0
var slot := ACTIVE[index]
for choice in range(unused.size()):
var next := unused.duplicate()
placed[slot] = next.pop_at(choice)
total += search(index + 1, placed, next, conflicting)
placed.erase(slot)
return total
func valid(placed: Dictionary, conflicting: bool) -> bool:
if placed.get(0) != "lemon_fizz":
return false
var toast_slot := 1 if placed.get(1) == "jam_toast" else 4
var is_edge_neighbor := adjacent(0, toast_slot)
var is_diagonal := toast_slot == WIDTH + 1
return is_edge_neighbor and (not conflicting or is_diagonal)
release_lab.gd
extends VBoxContainer
var output: Label
func start(title_text: String, lesson_number: int) -> void:
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
offset_left = 35.0
offset_top = 29.0
offset_right = -315.0
offset_bottom = -24.0
add_theme_constant_override("separation", 12)
var paper := ColorRect.new()
paper.color = Color("#142536")
paper.mouse_filter = Control.MOUSE_FILTER_IGNORE
get_parent().add_child(paper)
paper.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
get_parent().move_child(paper, 0)
var eyebrow := Label.new()
eyebrow.text = "TINY SHELF STUDIO / LESSON %d" % lesson_number
eyebrow.add_theme_font_size_override("font_size", 14)
eyebrow.add_theme_color_override("font_color", Color("#9ce3cf"))
add_child(eyebrow)
var title := Label.new()
title.text = title_text
title.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
title.add_theme_font_size_override("font_size", 29)
title.add_theme_color_override("font_color", Color("#ffe3ae"))
add_child(title)
output = Label.new()
output.custom_minimum_size.y = 132.0
output.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
output.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
output.add_theme_font_size_override("font_size", 20)
output.add_theme_color_override("font_color", Color("#ecf3f7"))
add_child(output)
func say(message: String) -> void:
output.text = message
func option(label: String, command: Callable) -> void:
var button := Button.new()
button.text = label
button.focus_mode = Control.FOCUS_ALL
button.custom_minimum_size.y = 48.0
button.add_theme_font_size_override("font_size", 18)
button.pressed.connect(command)
add_child(button)
pack_preview.gd
extends Control
func _draw() -> void:
var cream := Color("#fff1d7")
var turquoise := Color("#65c9b6")
var font := ThemeDB.fallback_font
draw_rect(Rect2(Vector2.ZERO, size), Color("#203951"))
draw_string(font, Vector2(20, 40), "THE PROTOTYPE SHELF", HORIZONTAL_ALIGNMENT_LEFT, -1, 15, cream)
draw_rect(Rect2(20, 60, 190, 3), turquoise)
front(Rect2(42, 124, 111, 143), Vector2(18, -12), Color("#ec9e69"), "LEMON", "FIZZ")
front(Rect2(100, 288, 86, 101), Vector2(15, -11), Color("#93afd9"), "MOON", "MILK")
draw_rect(Rect2(18, 396, 194, 7), Color("#5a7b8b"))
draw_string(font, Vector2(20, 437), "Invented packs · original art", HORIZONTAL_ALIGNMENT_LEFT, -1, 14, cream)
func front(rect: Rect2, depth: Vector2, ink: Color, name_top: String, name_bottom: String) -> void:
var top_left := rect.position
var top_right := Vector2(rect.end.x, rect.position.y)
var side_bottom := rect.end + depth
draw_colored_polygon(PackedVector2Array([top_left, top_left + depth, top_right + depth, top_right]), ink.lightened(0.28))
draw_colored_polygon(PackedVector2Array([top_right, top_right + depth, side_bottom, rect.end]), ink.darkened(0.28))
draw_rect(rect, ink)
draw_circle(rect.position + rect.size * Vector2(0.72, 0.27), 10, Color("#fff1d7"))
var font := ThemeDB.fallback_font
var label_color := Color("#162b3e")
draw_string(font, rect.position + Vector2(10, 57), name_top, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, label_color)
draw_string(font, rect.position + Vector2(10, 76), name_bottom, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, label_color)
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 Lab = preload("res://release_lab.gd")Load the practice panel's script before the game runs so the scene can give a VBoxContainer those useful methods. -
const PackArt = preload("res://pack_preview.gd")Load the drawing script for the original product forms. It has no effect on the checklist logic. -
const TITLE := "Design and validate an original display"Creates a constant named TITLE. The expression uses the text inside the quotes. Godot infers the type from the first value. -
const NUMBER := 41Creates a constant named NUMBER. The expression uses the whole number 41. Godot infers the type from the first value. -
var ui: VBoxContainerDeclares ui 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 preview := Control.new()Creates a variable named preview. The expression creates a new Control object. Godot infers the type from the first value. -
preview.set_script(PackArt)Attach the illustration behaviour to the new Control. The package drawing now belongs to this node. -
preview.mouse_filter = Control.MOUSE_FILTER_IGNOREThe illustration is decorative, so mouse input passes by it instead of stopping there. -
add_child(preview)Adds the new node to the scene tree so that Godot can run and draw it. -
preview.set_anchors_and_offsets_preset(Control.PRESET_RIGHT_WIDE)Anchor the illustration on the right and stretch its region vertically. -
preview.offset_left = -258.0Give the right-side artwork a left edge 258 pixels from its anchored edge. -
preview.offset_right = -28.0Give the right edge a 28-pixel margin. -
preview.offset_top = 32.0Stores the new value in preview.offset_top. The expression reads 32.0. -
preview.offset_bottom = -32.0Stores the new value in preview.offset_bottom. The expression reads -32.0. -
ui = VBoxContainer.new()Create a visual container that arranges its children in a column. -
ui.set_script(Lab)Calls ui.set_script with the values in its parentheses. -
add_child(ui)Adds the new node to the scene tree so that Godot can run and draw it. -
ui.start(TITLE, NUMBER)Set up the labelled teaching panel. The next instruction adds this lesson's buttons. -
build()The scene is in place. Now add this lesson's practice actions and initial prompt. -
const WIDTH := 4Creates a constant named WIDTH. The expression uses the whole number 4. Godot infers the type from the first value. -
const ACTIVE: Array[int] = [0, 1, 4]Indices 0 and 1 are adjacent on the top shelf. Index 4 sits directly beneath 0. -
const STOCK: Array[String] = ["lemon_fizz", "moon_milk", "jam_toast"]This practice brief has exactly one of each listed pack. -
func build() -> void: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. -
ui.say("Three minis, three slots. Find out which window rules have a solution.")Calls ui.say with the values in its parentheses. -
ui.option("Test both neighbours", report.bind(false))Calls ui.option with the values in its parentheses. -
ui.option("Test a conflicting brief", report.bind(true))Calls ui.option with the values in its parentheses. -
func report(conflicting: bool) -> void:Defines report, 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 total := search(0, {}, STOCK, conflicting)Start at the first active slot with no pieces placed and all stock still available. -
if total == 0:Checks total == 0. The indented instructions below run only if this test passes. -
ui.say("0 valid layouts. The diagonal rule conflicts with the edge rule.")Calls ui.say with the values in its parentheses. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
ui.say("%d valid layouts. Jam Toast can go beside or beneath Lemon Fizz." % total)Calls ui.say with the values in its parentheses. -
func adjacent(first: int, second: int) -> bool:Defines adjacent, 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 a := Vector2i(first % WIDTH, floori(float(first) / WIDTH))Remainder gives the column and the whole quotient gives the row. -
var b := Vector2i(second % WIDTH, floori(float(second) / WIDTH))Convert the second index the same way so both use the same coordinate basis. -
var distance := (a - b).abs()Subtract the pairs and take absolute values, so left and right movements are counted consistently. -
return distance.x + distance.y == 1A sum of one means the two cells touch along one edge. -
func search(index: int, placed: Dictionary, unused: Array[String], conflicting: bool) -> int:Defines search, 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 == ACTIVE.size():When all active slots have assignments, count this layout if the rules accept it. -
return 1 if valid(placed, conflicting) else 0Finishes the function and hands its result back to the caller. The expression chooses one of two values by checking the condition in the middle. -
var total := 0Creates a variable named total. The expression uses the whole number 0. Godot infers the type from the first value. -
var slot := ACTIVE[index]Creates a variable named slot. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value. -
for choice in range(unused.size()):Repeats the indented instructions for each value in range(unused.size()). -
var next := unused.duplicate()Give this branch its own list. Trying one use of a mini leaves other branches' stock intact. -
placed[slot] = next.pop_at(choice)Assign the chosen piece and remove it from the branch's remaining stock. -
total += search(index + 1, placed, next, conflicting)Explore the remainder of this branch and add every successful layout to the running count. -
placed.erase(slot)Undo the last trial placement so the next branch starts cleanly. -
return totalFinishes the function and hands its result back to the caller. The expression reads total. -
func valid(placed: Dictionary, conflicting: bool) -> bool:Defines valid, 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 placed.get(0) != "lemon_fizz":Reject the layout when Lemon Fizz is missing from the required starting slot. -
return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false. -
var toast_slot := 1 if placed.get(1) == "jam_toast" else 4Creates a variable named toast_slot. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
var is_edge_neighbor := adjacent(0, toast_slot)Creates a variable named is_edge_neighbor. The expression calls adjacent with the values in its parentheses. Godot infers the type from the first value. -
var is_diagonal := toast_slot == WIDTH + 1Slot 5 is one row down and one column across from slot 0. The practice shelf leaves it inactive. -
return is_edge_neighbor and (not conflicting or is_diagonal)The normal brief needs an edge neighbour. The conflicting brief asks for both an edge and a diagonal, which cannot be the same pair.
Read release_lab.gd line by line
-
extends VBoxContainerStarts with Godot's VBoxContainer type. This script gets the abilities of that type and adds the game's own rules. -
var output: LabelDeclares output for later use. A colon followed by a type says which kind of value belongs here. -
func start(title_text: String, lesson_number: int) -> void:Defines start, 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_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Start with a panel attached to all four edges of its parent. -
offset_left = 35.0Stores the new value in offset_left. The expression reads 35.0. -
offset_top = 29.0Stores the new value in offset_top. The expression reads 29.0. -
offset_right = -315.0Leave 315 pixels of space for artwork beside the exercises. -
offset_bottom = -24.0Stores the new value in offset_bottom. The expression reads -24.0. -
add_theme_constant_override("separation", 12)Calls add_theme_constant_override with the values in its parentheses. -
var paper := ColorRect.new()Creates a variable named paper. The expression creates a new ColorRect object. Godot infers the type from the first value. -
paper.color = Color("#142536")Stores the new value in paper.color. The expression builds a colour from these values. -
paper.mouse_filter = Control.MOUSE_FILTER_IGNORELet clicks pass through the background so it cannot interrupt a button. -
get_parent().add_child(paper)Calls get_parent with the values in its parentheses. -
paper.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Stretch the paper colour to the full scene edge. -
get_parent().move_child(paper, 0)Place the paper first in drawing order, behind the artwork and teaching panel. -
var eyebrow := Label.new()Creates a variable named eyebrow. The expression creates a new Label object. Godot infers the type from the first value. -
eyebrow.text = "TINY SHELF STUDIO / LESSON %d" % lesson_numberThe integer in lesson_number replaces %d in the heading string. -
eyebrow.add_theme_font_size_override("font_size", 14)Calls eyebrow.add_theme_font_size_override with the values in its parentheses. -
eyebrow.add_theme_color_override("font_color", Color("#9ce3cf"))Calls eyebrow.add_theme_color_override with the values in its parentheses. -
add_child(eyebrow)Adds the new node to the scene tree so that Godot can run and draw it. -
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 = title_textUpdates title.text, which controls the words a player sees. The expression reads title_text. -
title.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTAllow a long heading to wrap on word boundaries. -
title.add_theme_font_size_override("font_size", 29)Calls title.add_theme_font_size_override with the values in its parentheses. -
title.add_theme_color_override("font_color", Color("#ffe3ae"))Calls title.add_theme_color_override with the values in its parentheses. -
add_child(title)Adds the new node to the scene tree so that Godot can run and draw it. -
output = Label.new()Stores the new value in output. The expression creates a new Label object. -
output.custom_minimum_size.y = 132.0Keep a stable 132-pixel space for the result, so the buttons stay in place when the text changes. -
output.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTFit multi-line results to the current width without requiring horizontal scrolling. -
output.vertical_alignment = VERTICAL_ALIGNMENT_CENTERStores the new value in output.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_CENTER. -
output.add_theme_font_size_override("font_size", 20)Calls output.add_theme_font_size_override with the values in its parentheses. -
output.add_theme_color_override("font_color", Color("#ecf3f7"))Calls output.add_theme_color_override with the values in its parentheses. -
add_child(output)Adds the new node to the scene tree so that Godot can run and draw it. -
func say(message: String) -> void:Defines say, 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. -
output.text = messageReplace the practice status with a result the player can read. -
func option(label: String, command: Callable) -> void:Defines option, 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 = labelUpdates button.text, which controls the words a player sees. The expression reads label. -
button.focus_mode = Control.FOCUS_ALLKeep the button reachable by keyboard as well as a pointer or touch. -
button.custom_minimum_size.y = 48.0Give the control a taller hit area. -
button.add_theme_font_size_override("font_size", 18)Calls button.add_theme_font_size_override with the values in its parentheses. -
button.pressed.connect(command)Connect the press signal to the supplied action. That action runs when a learner chooses the button. -
add_child(button)Adds the new node to the scene tree so that Godot can run and draw it.
Read pack_preview.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. -
func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state. -
var cream := Color("#fff1d7")Creates a variable named cream. The expression builds a colour from these values. Godot infers the type from the first value. -
var turquoise := Color("#65c9b6")Creates a variable named turquoise. The expression builds a colour from these values. Godot infers the type from the first value. -
var font := ThemeDB.fallback_fontUse an engine-supplied font so the drawings and text need no extra download. -
draw_rect(Rect2(Vector2.ZERO, size), Color("#203951"))Fill the local area from the upper left to the current width and height. -
draw_string(font, Vector2(20, 40), "THE PROTOTYPE SHELF", HORIZONTAL_ALIGNMENT_LEFT, -1, 15, cream)Paints a piece of text with a font at a position measured from the node's origin. -
draw_rect(Rect2(20, 60, 190, 3), turquoise)Paints a rectangle at the given position and size. -
front(Rect2(42, 124, 111, 143), Vector2(18, -12), Color("#ec9e69"), "LEMON", "FIZZ")Draw the Lemon Fizz face with its width, height, invented name, ink and depth. -
front(Rect2(100, 288, 86, 101), Vector2(15, -11), Color("#93afd9"), "MOON", "MILK")Draw a smaller, bluer Moon Milk pack. The depth vector gives it a separate top and side. -
draw_rect(Rect2(18, 396, 194, 7), Color("#5a7b8b"))Paints a rectangle at the given position and size. -
draw_string(font, Vector2(20, 437), "Invented packs · original art", HORIZONTAL_ALIGNMENT_LEFT, -1, 14, cream)Paints a piece of text with a font at a position measured from the node's origin. -
func front(rect: Rect2, depth: Vector2, ink: Color, name_top: String, name_bottom: String) -> void:Defines front, 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 top_left := rect.positionCreates a variable named top_left. The expression reads rect.position. Godot infers the type from the first value. -
var top_right := Vector2(rect.end.x, rect.position.y)Use the right end and the upper y coordinate to find the top-right corner. -
var side_bottom := rect.end + depthOffset the bottom-right corner by the depth vector to finish the angled side. -
draw_colored_polygon(PackedVector2Array([top_left, top_left + depth, top_right + depth, top_right]), ink.lightened(0.28))Connect the four corners of the top, and lighten its colour as if light fell on it. -
draw_colored_polygon(PackedVector2Array([top_right, top_right + depth, side_bottom, rect.end]), ink.darkened(0.28))Connect the four corners of the right side. Darkening the ink makes the three-dimensional edge clearer. -
draw_rect(rect, ink)Paints a rectangle at the given position and size. -
draw_circle(rect.position + rect.size * Vector2(0.72, 0.27), 10, Color("#fff1d7"))Use a relative point inside the rectangle so the round badge is placed consistently on both packs. -
var font := ThemeDB.fallback_fontUse an engine-supplied font so the drawings and text need no extra download. -
var label_color := Color("#162b3e")Creates a variable named label_color. The expression builds a colour from these values. Godot infers the type from the first value. -
draw_string(font, rect.position + Vector2(10, 57), name_top, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, label_color)Write the product name on its face, with its own inset inside the shape. -
draw_string(font, rect.position + Vector2(10, 76), name_bottom, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, label_color)Write the product name on its face, with its own inset inside the shape.
Find and fix a bug
If the count rises every time you press the same button, make sure each search starts with a fresh dictionary and item list.
Try a change
Ages 10–12. Draw both solutions. Ages 13–16. Add a fourth active slot and make one layout the only valid answer.