Midnight Deck Dash · Lesson 41 of 50 · Publishing · About 40 min
The cinema is about to open on the Promenade. Design a projector parcel route that only your ship has, then ask Godot to check it.

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], nested for loops, Vector2i, pop_front(), Dictionary, route validation.
-
Sketch a delivery story
Give your deck a destination such as an outdoor cinema, café or first-aid desk. On squared paper, draw two corridors and a loop. Mark a single start, pickup, matching station and exit before tracing a route with a pencil.
Why it works Deliveries with distinct destinations give each route a purpose.
-
Write the deck as rows
Open checkpoint 41 in Godot. Select main.gd in FileSystem and find PLAN. Each string is one row and each character is one tile. Keep rows the same width. Use @ for start, a for the parcel, A for the booth and x for exit.
const PLAN: Array[String] = [Why it works Array[String] keeps an ordered list of text rows, like the lines in your drawing.
-
Inspect the symbols
Read scan() from top to bottom. The outer loop selects a row and the inner loop selects a column. Find the line that records each coordinate.
points[symbol] = Vector2i(column, row)Why it works Vector2i stores horizontal and vertical coordinates. The Dictionary looks up a coordinate from its symbol.
-
Check the whole route
Read reachable(). It starts a queue at one point, removes the oldest cell and adds unvisited walkable neighbours. The scanner checks start to parcel, parcel to station and station to exit.
var cell: Vector2i = pending.pop_front()Why it works The seen dictionary remembers visited cells. Looking at each cell at most once makes the search finish, including on a loop.
-
Break a copy on purpose
Press F5 and try both scanner buttons. Return to Script, edit the SEALED example and replace one wall with a floor so the station can be reached. Try a row with the wrong width too.
Why it works A useful test checks both a working route and an invalid one. This small tool checks a static one-parcel route before you bring in carts.
-
Bring your design into the game
Back up the full project. Open levels/catalog.json and copy the first one-parcel record. Keep the 15 × 9 grid used by the playable game. Set its own name and brief. Translate your grid marks to [column, row] coordinate pairs, then enter start, exit, walls, pickups and drops. Match each pickup and destination by their array position. Initially leave carts and lifts empty. Run the project and play your route.
Why it works The learning checkpoint checks the basic map. The game itself follows the full set of delivery rules.
Watch the values change
-
Scan the cinema plan All four symbols appear and the rows match in width.
What you see. The scanner can start its three checks. -
Follow parcel to booth The search reaches A through the lower corridor.
What you see. The route passes. -
Scan the sealed deck The booth is beyond a solid wall.
What you see. The scanner names the blocked leg.
Predict before you run All four markers are present but a wall seals the station. Will counting markers alone catch the error?
Reveal the answer
No. The reachability check finds that the parcel cannot reach its station.
Complete checkpoint
The example route passes. The sealed map reports delivery leg a to A is blocked.
main.gd
extends Control
const Lab = preload("res://release_lab.gd")
const TITLE := "Design a new delivery deck"
var ui: VBoxContainer
func _ready() -> void:
ui = VBoxContainer.new()
ui.set_script(Lab)
add_child(ui)
ui.start(TITLE)
build()
const PLAN: Array[String] = [
"#########",
"#@..a...#",
"#.###.#.#",
"#...A.x.#",
"#########"
]
const SEALED: Array[String] = [
"#########",
"#@..a...#",
"#########",
"#...A.x.#",
"#########"
]
func build() -> void:
ui.say("Try the cinema plan, then a deliberately sealed version.")
ui.option("Scan the cinema plan", func(): ui.say(scan(PLAN)))
ui.option("Scan a sealed deck", func(): ui.say(scan(SEALED)))
func scan(rows: Array[String]) -> String:
if rows.is_empty() or rows[0].is_empty():
return "Draw at least one tile."
var columns := rows[0].length()
var points := {}
for row in range(rows.size()):
if rows[row].length() != columns:
return "Row %d has a different width." % (row + 1)
for column in range(columns):
var symbol := rows[row][column]
if symbol not in "#.@aAx":
return "Unknown tile: " + symbol
if symbol in "@aAx":
if points.has(symbol):
return "Repeated job marker: " + symbol
points[symbol] = Vector2i(column, row)
for marker in ["@", "a", "A", "x"]:
if not points.has(marker):
return "Missing job marker: " + marker
for leg in ["@a", "aA", "Ax"]:
if not reachable(rows, points[leg[0]], points[leg[1]]):
return "Blocked delivery leg " + leg[0] + " to " + leg[1] + "."
return "Route passes: start → parcel → cinema booth → exit."
func reachable(rows: Array[String], start: Vector2i, target: Vector2i) -> bool:
var pending: Array[Vector2i] = [start]
var seen := {}
seen[start] = true
while not pending.is_empty():
var cell: Vector2i = pending.pop_front()
if cell == target:
return true
for delta in [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]:
var next: Vector2i = cell + delta
if next.x < 0 or next.y < 0 or next.y >= rows.size() or next.x >= rows[0].length():
continue
if rows[next.y][next.x] != "#" and not seen.has(next):
seen[next] = true
pending.append(next)
return false
release_lab.gd
extends VBoxContainer
var body: Label
func start(title_text: String) -> void:
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
offset_left = 34.0
offset_top = 24.0
offset_right = -34.0
offset_bottom = -24.0
add_theme_constant_override("separation", 12)
var title := Label.new()
title.text = title_text
title.add_theme_font_size_override("font_size", 31)
title.add_theme_color_override("font_color", Color("#f5cd85"))
add_child(title)
body = Label.new()
body.custom_minimum_size.y = 138.0
body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
body.add_theme_font_size_override("font_size", 19)
add_child(body)
var bg := ColorRect.new()
bg.color = Color("#132942")
bg.mouse_filter = Control.MOUSE_FILTER_IGNORE
bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
get_parent().add_child(bg)
get_parent().move_child(bg, 0)
func say(message: String) -> void:
body.text = message
func option(label: String, command: Callable) -> void:
var button := Button.new()
button.text = label
button.custom_minimum_size.y = 45.0
button.add_theme_font_size_override("font_size", 19)
button.pressed.connect(command)
add_child(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 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")Creates a constant named Lab. The expression prepares a resource at a fixed project path when the script is loaded. -
const TITLE := "Design a new delivery deck"Creates a constant named TITLE. The expression uses the text inside the quotes. 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. -
ui = VBoxContainer.new()Stores the new value in ui. The expression creates a new VBoxContainer object. -
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)Calls ui.start with the values in its parentheses. -
build()Calls build with the values in its parentheses. -
const PLAN: Array[String] = [Creates a constant named PLAN. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
"#########",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
"#@..a...#",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
"#.###.#.#",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
"#...A.x.#",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
"#########"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 SEALED: Array[String] = [Creates a constant named SEALED. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
"#########",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
"#@..a...#",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
"#########",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
"#...A.x.#",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
"#########"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. -
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("Try the cinema plan, then a deliberately sealed version.")Calls ui.say with the values in its parentheses. -
ui.option("Scan the cinema plan", func(): ui.say(scan(PLAN)))Calls ui.option with the values in its parentheses. -
ui.option("Scan a sealed deck", func(): ui.say(scan(SEALED)))Calls ui.option with the values in its parentheses. -
func scan(rows: Array[String]) -> String:Defines scan, 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 rows.is_empty() or rows[0].is_empty():Checks rows.is_empty() or rows[0].is_empty(). The indented instructions below run only if this test passes. -
return "Draw at least one tile."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
var columns := rows[0].length()Creates a variable named columns. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value. -
var points := {}Creates a variable named points. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value. -
for row in range(rows.size()):Repeats the indented instructions for each value in range(rows.size()). -
if rows[row].length() != columns:Checks rows[row].length() != columns. The indented instructions below run only if this test passes. -
return "Row %d has a different width." % (row + 1)Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
for column in range(columns):Repeats the indented instructions for each value in range(columns). -
var symbol := rows[row][column]Creates a variable named symbol. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value. -
if symbol not in "#.@aAx":Checks symbol not in "#.@aAx". The indented instructions below run only if this test passes. -
return "Unknown tile: " + symbolFinishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
if symbol in "@aAx":Checks symbol in "@aAx". The indented instructions below run only if this test passes. -
if points.has(symbol):Checks points.has(symbol). The indented instructions below run only if this test passes. -
return "Repeated job marker: " + symbolFinishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
points[symbol] = Vector2i(column, row)Stores the new value in points[symbol]. The expression packs whole-number x and y into one grid position. -
for marker in ["@", "a", "A", "x"]:Repeats the indented instructions for each value in ["@", "a", "A", "x"]. -
if not points.has(marker):Checks not points.has(marker). The indented instructions below run only if this test passes. -
return "Missing job marker: " + markerFinishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
for leg in ["@a", "aA", "Ax"]:Repeats the indented instructions for each value in ["@a", "aA", "Ax"]. -
if not reachable(rows, points[leg[0]], points[leg[1]]):Checks not reachable(rows, points[leg[0]], points[leg[1]]). The indented instructions below run only if this test passes. -
return "Blocked delivery leg " + leg[0] + " to " + leg[1] + "."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
return "Route passes: start → parcel → cinema booth → exit."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
func reachable(rows: Array[String], start: Vector2i, target: Vector2i) -> bool:Defines reachable, 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 pending: Array[Vector2i] = [start]Creates a variable named pending. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var seen := {}Creates a variable named seen. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value. -
seen[start] = trueStores the new value in seen[start]. The expression uses the yes-or-no value true. -
while not pending.is_empty():Keeps repeating while not pending.is_empty() stays true. The loop body should eventually change the result or leave with break. -
var cell: Vector2i = pending.pop_front()Creates a variable named cell. The expression takes the first item out of the list and returns it. The type after the colon says what kind of value it can hold. -
if cell == target:Checks cell == target. The indented instructions below run only if this test passes. -
return trueFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value true. -
for delta in [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]:Repeats the indented instructions for each value in [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]. -
var next: Vector2i = cell + deltaCreates a variable named next. The expression calculates a new value from the expressions on either side of the operator. The type after the colon says what kind of value it can hold. -
if next.x < 0 or next.y < 0 or next.y >= rows.size() or next.x >= rows[0].length():Checks next.x < 0 or next.y < 0 or next.y >= rows.size() or next.x >= rows[0].length(). The indented instructions below run only if this test passes. -
continueSkips the rest of this turn through the loop and moves on to the next item. -
if rows[next.y][next.x] != "#" and not seen.has(next):Checks rows[next.y][next.x] != "#" and not seen.has(next). The indented instructions below run only if this test passes. -
seen[next] = trueStores the new value in seen[next]. The expression uses the yes-or-no value true. -
pending.append(next)Adds an item to the end of a list. -
return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
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 body: LabelDeclares body for later use. A colon followed by a type says which kind of value belongs here. -
func start(title_text: String) -> 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)Positions this Control relative to the bounds of its parent. -
offset_left = 34.0Stores the new value in offset_left. The expression reads 34.0. -
offset_top = 24.0Stores the new value in offset_top. The expression reads 24.0. -
offset_right = -34.0Stores the new value in offset_right. The expression reads -34.0. -
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 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.add_theme_font_size_override("font_size", 31)Calls title.add_theme_font_size_override with the values in its parentheses. -
title.add_theme_color_override("font_color", Color("#f5cd85"))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. -
body = Label.new()Stores the new value in body. The expression creates a new Label object. -
body.custom_minimum_size.y = 138.0Stores the new value in body.custom_minimum_size.y. The expression reads 138.0. -
body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTStores the new value in body.autowrap_mode. The expression reads TextServer.AUTOWRAP_WORD_SMART. -
body.add_theme_font_size_override("font_size", 19)Calls body.add_theme_font_size_override with the values in its parentheses. -
add_child(body)Adds the new node to the scene tree so that Godot can run and draw it. -
var bg := ColorRect.new()Creates a variable named bg. The expression creates a new ColorRect object. Godot infers the type from the first value. -
bg.color = Color("#132942")Stores the new value in bg.color. The expression builds a colour from these values. -
bg.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates bg.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Positions this Control relative to the bounds of its parent. -
get_parent().add_child(bg)Calls get_parent with the values in its parentheses. -
get_parent().move_child(bg, 0)Calls get_parent with the values in its parentheses. -
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. -
body.text = messageUpdates body.text, which controls the words a player sees. The expression reads message. -
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.custom_minimum_size.y = 45.0Stores the new value in button.custom_minimum_size.y. The expression reads 45.0. -
button.add_theme_font_size_override("font_size", 19)Calls button.add_theme_font_size_override with the values in its parentheses. -
button.pressed.connect(command)Links a signal to the function that should run when the event happens. -
add_child(button)Adds the new node to the scene tree so that Godot can run and draw it.
Find and fix a bug
If a row is the wrong width, count the characters inside the quotes. A missing full stop or an extra space changes the count.
Try a change
Ages 10–12. Make a different corridor shape and ask a friend to trace the route. Ages 13–16. Add a second order in the game and test whether carrying one parcel at a time leaves a complete route.