Midnight Deck Dash · Lesson 50 of 50 · Publishing · About 45 min
Some players return after months at sea. Your update should remember their completed deliveries even after the ship's deck list changes.

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/49 when the lesson builds on prior work, or copy the checkpoints/50 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 JSON, Variant, typeof(), duplicate(), Dictionary, schema version, stable ID, regression fixtures.
-
Choose stable IDs
Open scripts/progress.gd in the full game and see how its ConfigFile stores the last completed job number. For a simple patch, keep the shipped job order. If you want to reorder jobs in a future version, design a fixed job ID for each one and make a versioned migration as practised in this lab. A display title can change independently.
Why it works If progress depends on list order, adding a job before an old job can show the wrong room as complete.
-
Compare old and new shapes
Open checkpoint 50. In this independent JSON exercise, OLD_SAVE lists a completed sample job under done. The new shape uses completed and adds captions. Read migrate(). Each accepted path returns a fresh Dictionary. This is a model for a future save format, separate from the full game’s existing ConfigFile.
return {"version": 2, "completed": old.duplicate(), "captions": true}Why it works A schema version tells the code which shape of data it has received. Returning a new object keeps the sample input intact.
-
Keep the evidence before changing a real file
This lab uses strings in memory. For a real release, copy a save file from an earlier test build and archive it first. On a test device install the old build, finish a job, update the game through its test track and open it again. Record the completed job and preferences before and after.
Why it works Testing the path players will use catches issues a clean install can miss.
-
Reject bad input without erasing it
Try Load unreadable sample and Load future-version sample. Check the parse result and version guard. In the real game, preserve the old file if a migration is unsupported. Show a helpful recovery message.
Why it works A new empty file would erase recovery evidence. Returning a result that signals ‘leave the source alone’ lets the caller choose a safe recovery path.
-
Validate before committing the update
In your own project, verify every record by type and stable job ID, check the new schema and write to a temporary file. Retain a backup, check the write result and replace the stored save only after the new file is complete. Test clean install, update and malformed save.
Why it works A partial write can corrupt a good save. Validating then committing makes the update easier to recover from.
-
Ship with a versioned change log
Write one factual release note for the fix, bump your platform build numbers, export a new practice build and test the same fixtures again. The adult publisher repeats the approval and store rollout steps from lesson 49.
Why it works The completed test log shows which update works with existing progress and helps maintain the project after the course.
Watch the values change
-
Read version 1 The old save lists promenade-intro under done.
What you see. The lab copies it to completed and sets default captions. -
Read future data The version number is 9.
What you see. The lab keeps the original source intact. -
Read malformed text The parser reports an error.
What you see. The sample asks the caller to keep the original source.
Predict before you run The display order changes but the completed job ID stays the same. Does the saved delivery still refer to the correct job?
Reveal the answer
Yes. A stable ID attaches progress to the job itself. A list index could start referring to a different job after the reorder.
Complete checkpoint
Version 1 upgrades to version 2 and retains one job. Current data retains captions false. Invalid and future saves are left intact.
main.gd
extends Control
const Lab = preload("res://release_lab.gd")
const TITLE := "Release an update without losing progress"
var ui: VBoxContainer
func _ready() -> void:
ui = VBoxContainer.new()
ui.set_script(Lab)
add_child(ui)
ui.start(TITLE)
build()
const OLD_SAVE := "{\"version\":1,\"done\":[\"promenade-intro\"]}"
const CURRENT := "{\"version\":2,\"completed\":[\"atrium-matinee\"] ,\"captions\":false}"
const FUTURE := "{\"version\":9,\"completed\":[\"service-pantry\"]}"
func build() -> void:
ui.say("The migration lab reads sample copies in memory. It never writes a player's file.")
ui.option("Load sample version 1", show_save.bind(OLD_SAVE))
ui.option("Load current version", show_save.bind(CURRENT))
ui.option("Load unreadable sample", show_save.bind("{oops"))
ui.option("Load future-version sample", show_save.bind(FUTURE))
func show_save(raw: String) -> void:
var result := migrate(raw)
if result.is_empty():
ui.say("Save cannot be upgraded here. Keep the source intact.")
return
ui.say("Save v%d • %d completed • captions %s. Original source kept." % [result["version"], result["completed"].size(), str(result["captions"])])
func migrate(raw: String) -> Dictionary:
var parser := JSON.new()
if parser.parse(raw) != OK or not parser.data is Dictionary:
return {}
var snapshot: Dictionary = parser.data
var version: Variant = snapshot.get("version", null)
if version != 1 and version != 2:
return {}
if version == 1:
var old: Variant = snapshot.get("done", null)
if not valid_ids(old):
return {}
return {"version": 2, "completed": old.duplicate(), "captions": true}
var completed: Variant = snapshot.get("completed", null)
var captions: Variant = snapshot.get("captions", null)
if not valid_ids(completed) or not captions is bool:
return {}
return {"version": 2, "completed": completed.duplicate(), "captions": captions}
func valid_ids(value: Variant) -> bool:
if not value is Array:
return false
for job in value:
if not job is String or job.is_empty():
return false
return true
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 := "Release an update without losing progress"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 OLD_SAVE := "{\"version\":1,\"done\":[\"promenade-intro\"]}"Creates a constant named OLD_SAVE. The expression uses the text inside the quotes. Godot infers the type from the first value. -
const CURRENT := "{\"version\":2,\"completed\":[\"atrium-matinee\"] ,\"captions\":false}"Creates a constant named CURRENT. The expression uses the text inside the quotes. Godot infers the type from the first value. -
const FUTURE := "{\"version\":9,\"completed\":[\"service-pantry\"]}"Creates a constant named FUTURE. The expression uses the text inside the quotes. Godot infers the type from the first value. -
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("The migration lab reads sample copies in memory. It never writes a player's file.")Calls ui.say with the values in its parentheses. -
ui.option("Load sample version 1", show_save.bind(OLD_SAVE))Calls ui.option with the values in its parentheses. -
ui.option("Load current version", show_save.bind(CURRENT))Calls ui.option with the values in its parentheses. -
ui.option("Load unreadable sample", show_save.bind("{oops"))Calls ui.option with the values in its parentheses. -
ui.option("Load future-version sample", show_save.bind(FUTURE))Calls ui.option with the values in its parentheses. -
func show_save(raw: String) -> void:Defines show save, 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 result := migrate(raw)Creates a variable named result. The expression calls migrate with the values in its parentheses. Godot infers the type from the first value. -
if result.is_empty():Checks result.is_empty(). The indented instructions below run only if this test passes. -
ui.say("Save cannot be upgraded here. Keep the source intact.")Calls ui.say with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
ui.say("Save v%d • %d completed • captions %s. Original source kept." % [result["version"], result["completed"].size(), str(result["captions"])])Calls ui.say with the values in its parentheses. -
func migrate(raw: String) -> Dictionary:Defines migrate, 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 parser := JSON.new()Creates a variable named parser. The expression creates a new JSON object. Godot infers the type from the first value. -
if parser.parse(raw) != OK or not parser.data is Dictionary:Checks parser.parse(raw) != OK or not parser.data is Dictionary. The indented instructions below run only if this test passes. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var snapshot: Dictionary = parser.dataCreates a variable named snapshot. The expression reads parser.data. The type after the colon says what kind of value it can hold. -
var version: Variant = snapshot.get("version", null)Creates a variable named version. The expression looks up a named or indexed value, using a fallback when the call gives one. The type after the colon says what kind of value it can hold. -
if version != 1 and version != 2:Checks version != 1 and version != 2. The indented instructions below run only if this test passes. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
if version == 1:Checks version == 1. The indented instructions below run only if this test passes. -
var old: Variant = snapshot.get("done", null)Creates a variable named old. The expression looks up a named or indexed value, using a fallback when the call gives one. The type after the colon says what kind of value it can hold. -
if not valid_ids(old):Checks not valid_ids(old). The indented instructions below run only if this test passes. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
return {"version": 2, "completed": old.duplicate(), "captions": true}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var completed: Variant = snapshot.get("completed", null)Creates a variable named completed. The expression looks up a named or indexed value, using a fallback when the call gives one. The type after the colon says what kind of value it can hold. -
var captions: Variant = snapshot.get("captions", null)Creates a variable named captions. The expression looks up a named or indexed value, using a fallback when the call gives one. The type after the colon says what kind of value it can hold. -
if not valid_ids(completed) or not captions is bool:Checks not valid_ids(completed) or not captions is bool. The indented instructions below run only if this test passes. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
return {"version": 2, "completed": completed.duplicate(), "captions": captions}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
func valid_ids(value: Variant) -> bool:Defines valid ids, 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 not value is Array:Checks not value is Array. The indented instructions below run only if this test passes. -
return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false. -
for job in value:Repeats the indented instructions for each value in value. -
if not job is String or job.is_empty():Checks not job is String or job.is_empty(). The indented instructions below run only if this test passes. -
return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false. -
return trueFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value true.
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 save appears empty after an update, keep a copy of the original and compare the expected fields and stable IDs before writing a replacement.
Try a change
Ages 10–12. Predict what the four sample buttons show and check your answers. Ages 13–16. Add a v2-to-v3 migration and prove that running it a second time leaves the same progress.