Museum of Lost Lights · Lesson 50 of 50 · Publishing · About 45 min
The museum’s opening night is nearly here. Play the finished route once more, check that a visitor who already saved their progress can return after an update, and leave a written record for the next developer.

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.parse, Error, Variant, Dictionary.get, is, return, clampi, save migration.
-
Open the checkpoint in Godot
Extract the course files. In Godot Project Manager, choose Import and point it to this lesson’s project.godot. Double-click main.gd in FileSystem to open the script. Press F6 to run the current scene once main.tscn is open, or F5 to run the project. This checkpoint uses example save text in memory. Open the finished game as a separate project to play all of the reference levels.
const UI = preload("res://lesson_ui.gd")Why it works This small project lets you see one release skill at a time. The finished Museum of Lost Lights is a second, independent project. Keep both projects in their own folders.
-
Play the full release candidate
In the finished game, start from a fresh profile. Reach the last intended gallery, try undo and hints, change sound settings, and close and reopen the app during a puzzle. Repeat in airplane mode. Use the actual mobile build and device when available.
Why it works A candidate is the specific build you intend to submit. Test that exact build and record its number so you can compare any report against the correct version.
-
Read a save without trusting its shape
Follow _migrate. JSON.new makes a decoder. The parse call attempts to read the text and returns an error code. Only read decoder.data after parse returns OK. The variable parsed uses Variant because a successful decode can return a list, a number, a dictionary or another type. The next guard checks that the result is a Dictionary before reading its keys.
if decoder.parse(raw) != OK:Why it works If the save was truncated or edited, parsing may fail or yield the wrong type. Guard checks keep the game from treating invalid data like a real save.
-
Translate old saves into your current format
Run the old example first. It used schema number 1 and stored cleared. The current format calls that number completed and adds a mute setting. The if branch reads the old name, then writes the current names. The clampi function keeps the result between zero and the supported level count.
var old_count: Variant = parsed.get("cleared", 0)Why it works A migration reads past data in order to keep progress usable after a game update. The same function handles current saves and rejects unrecognised formats here.
-
Test your update from both directions
Test a fresh install of the new build and an in-place update from a previous test build that has progress. Save, mute and quit in the old version first. Open the new version and check the expected data. Test an intentionally broken fixture only in a disposable test copy.
Why it works Fresh installs reveal missing defaults. In-place updates reveal unexpected loss of progress. A protected test copy avoids overwriting a real player’s save.
-
Write the handover
Record the game’s version, store build number, changes players can see, device tests, remaining limitations and where the source project and artwork masters are kept. Explain how to report a bug with a replay path. The publisher handles the release control and checks the published listing when the store approves it.
Why it works Clear handover notes let someone else fix or expand your game without guessing how you built it.
-
Read the result, then apply it to your game
Celebrate by having someone play your own distinct puzzle. Keep their feedback as your first update issue. Make a second copy of the finished project and archive the source and asset licence register with the release version.
Why it works The checkpoint shows what to look for. Your game’s real result comes from testing your own build, assets and settings.
Watch the values change
-
Load old example Schema 1 and cleared 4.
What you see. The new example reports four completed puzzles and sound on. -
Load current example Schema 2 and completed 7, muted true.
What you see. The new example reports seven completed puzzles and sound muted. -
Load broken example The JSON text cannot be parsed.
What you see. The demo returns the starting settings and a recovery note.
Predict before you run Why test an update after saving progress in an older build?
Reveal the answer
The latest app could work on a fresh install and still fail to understand an old save. An in-place update tests the transition that existing players will actually experience.
Complete checkpoint
Old saves keep four completed puzzles. The current example keeps seven puzzles and muted sound. The broken example opens at a fresh practice state without writing any real save file.
main.gd
extends Control
const UI = preload("res://lesson_ui.gd")
const LEVELS := 12
var output: Label
func _ready() -> void:
var column := UI.build(self, "Museum update lab", "Try in-memory saves, then test your own release candidate with a previous version.")
UI.button(column, "Load schema 1 example", _show_save.bind('{"schema":1,"cleared":4}'))
UI.button(column, "Load schema 2 example", _show_save.bind('{"schema":2,"completed":7,"muted":true}'))
UI.button(column, "Load broken example", _show_save.bind("{incomplete"))
output = UI.message(column, "Choose a sample. None of these buttons writes a save file.")
func _show_save(raw: String) -> void:
var result := _migrate(raw)
var sound := "muted" if result.muted else "on"
output.text = "%s Completed: %d of %d. Sound: %s." % [result.note, result.completed, LEVELS, sound]
func _fresh(message: String) -> Dictionary:
return {"completed": 0, "muted": false, "note": message}
func _migrate(raw: String) -> Dictionary:
var decoder := JSON.new()
if decoder.parse(raw) != OK:
return _fresh("Could not read this practice save.")
var parsed: Variant = decoder.data
if not parsed is Dictionary:
return _fresh("Practice save was not a dictionary.")
var schema: Variant = parsed.get("schema", 0)
if schema == 1:
var old_count: Variant = parsed.get("cleared", 0)
if not _is_whole_number(old_count):
return _fresh("Old progress was not a whole number.")
return {"completed": clampi(int(old_count), 0, LEVELS), "muted": false, "note": "Old format converted."}
if schema == 2:
var total: Variant = parsed.get("completed", 0)
var muted: Variant = parsed.get("muted", false)
if not _is_whole_number(total) or not muted is bool:
return _fresh("Current save had an invalid value.")
return {"completed": clampi(int(total), 0, LEVELS), "muted": muted, "note": "Current format restored."}
return _fresh("This practice format is unknown.")
func _is_whole_number(value: Variant) -> bool:
if value is int:
return true
if value is float:
return is_finite(value) and value == floor(value)
return false
lesson_ui.gd
extends RefCounted
static func build(screen: Control, heading: String, opening: String) -> VBoxContainer:
var margins := MarginContainer.new()
screen.add_child(margins)
margins.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
for edge in ["left", "right", "top", "bottom"]:
margins.add_theme_constant_override("margin_" + edge, 24)
var scroll := ScrollContainer.new()
margins.add_child(scroll)
var column := VBoxContainer.new()
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
scroll.add_child(column)
column.add_theme_constant_override("separation", 12)
var title := Label.new()
title.text = heading
title.add_theme_font_size_override("font_size", 30)
column.add_child(title)
message(column, opening)
return column
static func message(column: VBoxContainer, text: String) -> Label:
var line := Label.new()
line.text = text
line.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
column.add_child(line)
return line
static func button(column: Container, caption: String, action: Callable) -> Button:
var control := Button.new()
control.text = caption
control.custom_minimum_size.y = 48
control.pressed.connect(action)
column.add_child(control)
return control
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 UI = preload("res://lesson_ui.gd")Creates a constant named UI. The expression prepares a resource at a fixed project path when the script is loaded. -
const LEVELS := 12Creates a constant named LEVELS. The expression uses the whole number 12. Godot infers the type from the first value. -
var output: LabelDeclares output 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 column := UI.build(self, "Museum update lab", "Try in-memory saves, then test your own release candidate with a previous version.")Creates a variable named column. The expression calls UI.build with the values in its parentheses. Godot infers the type from the first value. -
UI.button(column, "Load schema 1 example", _show_save.bind('{"schema":1,"cleared":4}'))Calls UI.button with the values in its parentheses. -
UI.button(column, "Load schema 2 example", _show_save.bind('{"schema":2,"completed":7,"muted":true}'))Calls UI.button with the values in its parentheses. -
UI.button(column, "Load broken example", _show_save.bind("{incomplete"))Calls UI.button with the values in its parentheses. -
output = UI.message(column, "Choose a sample. None of these buttons writes a save file.")Stores the new value in output. The expression calls UI.message 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. -
var sound := "muted" if result.muted else "on"Creates a variable named sound. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
output.text = "%s Completed: %d of %d. Sound: %s." % [result.note, result.completed, LEVELS, sound]Updates output.text, which controls the words a player sees. The expression uses the text inside the quotes. -
func _fresh(message: String) -> Dictionary:Defines fresh, 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. -
return {"completed": 0, "muted": false, "note": message}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
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 decoder := JSON.new()Creates a variable named decoder. The expression creates a new JSON object. Godot infers the type from the first value. -
if decoder.parse(raw) != OK:Checks decoder.parse(raw) != OK. The indented instructions below run only if this test passes. -
return _fresh("Could not read this practice save.")Finishes the function and hands its result back to the caller. The expression calls _fresh with the values in its parentheses. -
var parsed: Variant = decoder.dataCreates a variable named parsed. The expression reads decoder.data. The type after the colon says what kind of value it can hold. -
if not parsed is Dictionary:Checks not parsed is Dictionary. The indented instructions below run only if this test passes. -
return _fresh("Practice save was not a dictionary.")Finishes the function and hands its result back to the caller. The expression calls _fresh with the values in its parentheses. -
var schema: Variant = parsed.get("schema", 0)Creates a variable named schema. 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 schema == 1:Checks schema == 1. The indented instructions below run only if this test passes. -
var old_count: Variant = parsed.get("cleared", 0)Creates a variable named old_count. 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 _is_whole_number(old_count):Checks not _is_whole_number(old_count). The indented instructions below run only if this test passes. -
return _fresh("Old progress was not a whole number.")Finishes the function and hands its result back to the caller. The expression calls _fresh with the values in its parentheses. -
return {"completed": clampi(int(old_count), 0, LEVELS), "muted": false, "note": "Old format converted."}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
if schema == 2:Checks schema == 2. The indented instructions below run only if this test passes. -
var total: Variant = parsed.get("completed", 0)Creates a variable named total. 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 muted: Variant = parsed.get("muted", false)Creates a variable named muted. 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 _is_whole_number(total) or not muted is bool:Checks not _is_whole_number(total) or not muted is bool. The indented instructions below run only if this test passes. -
return _fresh("Current save had an invalid value.")Finishes the function and hands its result back to the caller. The expression calls _fresh with the values in its parentheses. -
return {"completed": clampi(int(total), 0, LEVELS), "muted": muted, "note": "Current format restored."}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
return _fresh("This practice format is unknown.")Finishes the function and hands its result back to the caller. The expression calls _fresh with the values in its parentheses. -
func _is_whole_number(value: Variant) -> bool:Defines is whole number, 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 value is int:Checks value is int. 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. -
if value is float:Checks value is float. The indented instructions below run only if this test passes. -
return is_finite(value) and value == floor(value)Finishes the function and hands its result back to the caller. The expression calls is_finite with the values in its parentheses. -
return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
Read lesson_ui.gd line by line
-
extends RefCountedStarts with Godot's RefCounted type. This script gets the abilities of that type and adds the game's own rules. -
static func build(screen: Control, heading: String, opening: String) -> VBoxContainer: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. -
var margins := MarginContainer.new()Creates a variable named margins. The expression creates a new MarginContainer object. Godot infers the type from the first value. -
screen.add_child(margins)Adds the new node to the scene tree so that Godot can run and draw it. -
margins.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Positions this Control relative to the bounds of its parent. -
for edge in ["left", "right", "top", "bottom"]:Repeats the indented instructions for each value in ["left", "right", "top", "bottom"]. -
margins.add_theme_constant_override("margin_" + edge, 24)Calls margins.add_theme_constant_override with the values in its parentheses. -
var scroll := ScrollContainer.new()Creates a variable named scroll. The expression creates a new ScrollContainer object. Godot infers the type from the first value. -
margins.add_child(scroll)Adds the new node to the scene tree so that Godot can run and draw it. -
var column := VBoxContainer.new()Creates a variable named column. The expression creates a new VBoxContainer object. Godot infers the type from the first value. -
column.size_flags_horizontal = Control.SIZE_EXPAND_FILLStores the new value in column.size_flags_horizontal. The expression reads Control.SIZE_EXPAND_FILL. -
scroll.add_child(column)Adds the new node to the scene tree so that Godot can run and draw it. -
column.add_theme_constant_override("separation", 12)Calls column.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 = headingUpdates title.text, which controls the words a player sees. The expression reads heading. -
title.add_theme_font_size_override("font_size", 30)Calls title.add_theme_font_size_override with the values in its parentheses. -
column.add_child(title)Adds the new node to the scene tree so that Godot can run and draw it. -
message(column, opening)Calls message with the values in its parentheses. -
return columnFinishes the function and hands its result back to the caller. The expression reads column. -
static func message(column: VBoxContainer, text: String) -> Label:Defines message, 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 line := Label.new()Creates a variable named line. The expression creates a new Label object. Godot infers the type from the first value. -
line.text = textUpdates line.text, which controls the words a player sees. The expression reads text. -
line.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTStores the new value in line.autowrap_mode. The expression reads TextServer.AUTOWRAP_WORD_SMART. -
column.add_child(line)Adds the new node to the scene tree so that Godot can run and draw it. -
return lineFinishes the function and hands its result back to the caller. The expression reads line. -
static func button(column: Container, caption: String, action: Callable) -> Button:Defines 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 = captionUpdates control.text, which controls the words a player sees. The expression reads caption. -
control.custom_minimum_size.y = 48Stores the new value in control.custom_minimum_size.y. The expression uses the whole number 48. -
control.pressed.connect(action)Links a signal to the function that should run when the event happens. -
column.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.
Find and fix a bug
If all old saves show zero, compare the original key with the key used in the schema 1 branch. The old sample uses cleared, while the current one uses completed.
Try a change
Ages 10–12: load all three samples and explain the recovery path. Ages 13–16: add a future schema 3 migration in a disposable copy, expand the regression cases and keep a written record of which versions you tested.