Market Day London · Lesson 50 of 50 · Publishing · About 43 min
Nia has completed two shifts. A new version adds a sound setting. Her badges should still be there after the update.

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_string(), Variant, type guards, match, clampi(), save schema.
-
Separate two save shapes
Import checkpoint 50, open main.gd and press F5. Try old, new and unreadable samples. Schema 1 has a shift count. Schema 2 renames that field and adds a sound preference.
Why it works A schema is an agreed shape for information. A version number tells the program which shape it should see.
-
Check the parser output
Open migrate(). The lab asks whether the JSON result is a dictionary before reading its keys. Try the array example to see the guard work.
if not (data is Dictionary):Why it works An array and a dictionary are both valid JSON shapes. Only the expected shape suits this save.
-
Read old and new fields
Follow the match branches. The old count lives under completed_shifts and migrates to completed, with a default for sound. The new record keeps its stated sound value. If a saved count is absent, the lab flags recovery.
Why it works Migration preserves compatible progress and supplies a safe value for a new option.
-
Protect the saved copy
Keep a backup when testing migration of actual files. Write new records only after validating them. The classroom samples use JSON in memory. Inspect the reference game's progress script separately and use its own save format for a real update test.
Why it works Never overwrite the only save you have when the program cannot read it.
-
Run a real upgrade trial
With an adult, install an older authorised test build on a supported device and complete two shifts. Upgrade to your newer build with the same package identity, then compare badges, unlocked shifts and settings.
Why it works A genuine upgrade tests packaging and storage as well as the migration logic.
-
Complete your own handover
Save your original market shift and editable project. Include setup instructions, build numbers, a device result, asset credits, factual disclosure notes and a clear next feature. Show someone else how to complete an order.
Why it works Small, verified features and a reproducible handover help another person continue the work.
Watch the values change
-
Load schema 1 Two shifts were completed under the old key.
What you see. The new form keeps two and defaults sound to on. -
Load schema 2 Three are complete, with sound off.
What you see. The record keeps both values. -
Load an array The shape has no agreed save fields.
What you see. The lab suggests preserving the source and recovering.
Predict before you run If the new game cannot read an old save, should it replace it with zero progress immediately?
Reveal the answer
Keep the original safe, then provide a recovery choice. Test known older records before publishing an update.
Complete checkpoint
The old example keeps two completed shifts, the new example keeps three and muted sound, and the incompatible example offers recovery.
main.gd
extends Control
const Lab = preload("res://release_lab.gd")
const TITLE = "Ship an update that preserves market badges"
var ui: VBoxContainer
func _ready() -> void:
ui = VBoxContainer.new()
ui.set_script(Lab)
add_child(ui)
ui.start(TITLE)
build()
const OLD_SAVE := '{"schema":1,"completed_shifts":2}'
const NEW_SAVE := '{"schema":2,"completed":3,"sound":false}'
const UNREADABLE := '["a shift",2]'
func build() -> void:
ui.say("Practise migrating temporary JSON. No real badge files are changed.")
ui.option("Read an old badge record", report.bind(OLD_SAVE))
ui.option("Read a current badge record", report.bind(NEW_SAVE))
ui.option("Read an incompatible record", report.bind(UNREADABLE))
func report(raw: String) -> void:
var result := migrate(raw)
if result.is_empty():
ui.say("Unrecognised save. Keep the source and offer recovery.")
else:
ui.say("Schema %d. Completed shifts: %d. Sound: %s." % [
result.schema, result.completed, "on" if result.sound else "off"
])
func migrate(raw: String) -> Dictionary:
var data: Variant = JSON.parse_string(raw)
if not (data is Dictionary):
return {}
var schema: Variant = data.get("schema")
if not (schema is int or schema is float) or (schema != 1 and schema != 2):
return {}
match int(schema):
1:
var old_count: Variant = data.get("completed_shifts")
if not (old_count is int or old_count is float):
return {}
return {"schema": 2, "completed": clampi(int(old_count), 0, 9), "sound": true}
2:
var count: Variant = data.get("completed")
if not (count is int or count is float) or not (data.get("sound") is bool):
return {}
return {"schema": 2, "completed": clampi(int(count), 0, 9), "sound": data.sound}
_:
return {}
release_lab.gd
extends VBoxContainer
var output: Label
func start(title_text: String) -> void:
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
offset_left = 32.0
offset_top = 28.0
offset_right = -32.0
offset_bottom = -28.0
add_theme_constant_override("separation", 12)
var background := ColorRect.new()
background.color = Color("#20342e")
background.mouse_filter = Control.MOUSE_FILTER_IGNORE
get_parent().add_child(background)
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
get_parent().move_child(background, 0)
var title := Label.new()
title.text = title_text
title.add_theme_font_size_override("font_size", 32)
title.add_theme_color_override("font_color", Color("#f3c991"))
add_child(title)
output = Label.new()
output.custom_minimum_size.y = 151.0
output.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
output.add_theme_font_size_override("font_size", 19)
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.custom_minimum_size.y = 46.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 = "Ship an update that preserves market badges"Creates a constant named TITLE. The expression uses the text inside the quotes. -
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 := '{"schema":1,"completed_shifts":2}'Creates a constant named OLD_SAVE. The expression uses the text inside the quotes. Godot infers the type from the first value. -
const NEW_SAVE := '{"schema":2,"completed":3,"sound":false}'Creates a constant named NEW_SAVE. The expression uses the text inside the quotes. Godot infers the type from the first value. -
const UNREADABLE := '["a shift",2]'Creates a constant named UNREADABLE. 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("Practise migrating temporary JSON. No real badge files are changed.")Calls ui.say with the values in its parentheses. -
ui.option("Read an old badge record", report.bind(OLD_SAVE))Calls ui.option with the values in its parentheses. -
ui.option("Read a current badge record", report.bind(NEW_SAVE))Calls ui.option with the values in its parentheses. -
ui.option("Read an incompatible record", report.bind(UNREADABLE))Calls ui.option with the values in its parentheses. -
func report(raw: String) -> 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 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("Unrecognised save. Keep the source and offer recovery.")Calls ui.say with the values in its parentheses. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
ui.say("Schema %d. Completed shifts: %d. Sound: %s." % [Calls ui.say with the values in its parentheses. -
result.schema, result.completed, "on" if result.sound else "off"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. -
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 data: Variant = JSON.parse_string(raw)Creates a variable named data. The expression tries to turn JSON text back into a value. The type after the colon says what kind of value it can hold. -
if not (data is Dictionary):Checks not (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 schema: Variant = data.get("schema")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 not (schema is int or schema is float) or (schema != 1 and schema != 2):Checks not (schema is int or schema is float) or (schema != 1 and schema != 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. -
match int(schema):Compares int(schema) to the patterns below and runs the first matching branch. -
1:Starts the instructions for this branch. The indented lines belong together. -
var old_count: Variant = data.get("completed_shifts")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 (old_count is int or old_count is float):Checks not (old_count is int or old_count is float). 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 {"schema": 2, "completed": clampi(int(old_count), 0, 9), "sound": true}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
2:Starts the instructions for this branch. The indented lines belong together. -
var count: Variant = data.get("completed")Creates a variable named 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 (count is int or count is float) or not (data.get("sound") is bool):Checks not (count is int or count is float) or not (data.get("sound") 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 {"schema": 2, "completed": clampi(int(count), 0, 9), "sound": data.sound}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
_:Handles every match value that the branches above did not handle. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key.
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) -> 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 = 32.0Stores the new value in offset_left. The expression reads 32.0. -
offset_top = 28.0Stores the new value in offset_top. The expression reads 28.0. -
offset_right = -32.0Stores the new value in offset_right. The expression reads -32.0. -
offset_bottom = -28.0Stores the new value in offset_bottom. The expression reads -28.0. -
add_theme_constant_override("separation", 12)Calls add_theme_constant_override with the values in its parentheses. -
var background := ColorRect.new()Creates a variable named background. The expression creates a new ColorRect object. Godot infers the type from the first value. -
background.color = Color("#20342e")Stores the new value in background.color. The expression builds a colour from these values. -
background.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates background.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
get_parent().add_child(background)Calls get_parent with the values in its parentheses. -
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Positions this Control relative to the bounds of its parent. -
get_parent().move_child(background, 0)Calls get_parent 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", 32)Calls title.add_theme_font_size_override with the values in its parentheses. -
title.add_theme_color_override("font_color", Color("#f3c991"))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 = 151.0Stores the new value in output.custom_minimum_size.y. The expression reads 151.0. -
output.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTStores the new value in output.autowrap_mode. The expression reads TextServer.AUTOWRAP_WORD_SMART. -
output.add_theme_font_size_override("font_size", 19)Calls output.add_theme_font_size_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 = messageUpdates output.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 = 46.0Stores the new value in button.custom_minimum_size.y. The expression reads 46.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 the sound setting becomes a word rather than a Boolean, check that false in JSON has no quotation marks.
Try a change
Ages 10–12. Compare the three sample results. Ages 13–16. Add an unsupported future schema and show what the safe recovery message says.