Cabin Crew Express · Lesson 50 of 50 · Publishing · About 42 min
Ari's team adds a sound preference after players have finished two flights. An update should still recognise those earlier accomplishments.

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, is Dictionary, match, clampi(), schema version.
-
Compare the two save examples
Import checkpoint 50, open main.gd and press F5. The old sample uses schema 1 and stores a flight count; the new sample uses schema 2 and gives fields distinct names including sound.
Why it works A schema is an agreed shape for information. Store a schema number so code can decide how to read a saved version.
-
Read the type guards
Find migrate(). It checks that JSON parsed into a dictionary before it asks for schema. Look at the branches after match. Try the examples in the order old, new and damaged.
if not (data is Dictionary):Why it works Type guards let code respond to bad input instead of looking for a field in a value that has no fields.
-
Translate an old success
In schema 1's branch, find completed_flights. Copy it into the new format's completed field. Set a sensible default for the sound option. Inspect the completed count displayed by the lab.
Why it works Translate compatible information and supply a documented value for new settings.
-
Preserve a damaged file
Try Damaged-save example. A real app could preserve a backup and provide a recovery choice before writing anything. The lab holds examples in memory. Practise on copies. The reference project uses ConfigFile in scripts/progress.gd for the flight medal record. This exercise uses a separate classroom JSON format.
Why it works Recovering cautiously makes it possible to diagnose what happened and avoids overwriting the only saved progress.
-
Test an update on a device
On a permitted device and with an adult, install the older test build and complete two flights. Upgrade to a newer build with the same identity and check progress, settings and new game. Check actual files and UI using your build's save format.
Why it works A genuine update test can reveal packaging or storage differences that the JSON example does not model.
-
Finish your project handover
Save the editable Godot project and your original cabin mission. Include launch instructions, roles for the adult publisher, device results, art credits and factual privacy notes. Write one next improvement for a future build.
Why it works A small, tested game, clear evidence and editable source complete the course challenge.
Watch the values change
-
Load schema 1 Two flights were completed under the old field name.
What you see. The migrated record still shows two, with sound on by default. -
Load schema 2 Three were completed and the sound option is false.
What you see. The new record preserves three and the silent setting. -
Load an incompatible sample The parser returns an array instead of a dictionary.
What you see. The lab displays a recovery note.
Predict before you run Should an update silently progress from two completed flights to zero because a field name changed?
Reveal the answer
No. Convert the old field into the new shape, then check completed flights on the supported device.
Complete checkpoint
The old sample shows two completed flights and sound on. The new one preserves three and sound off. The incompatible sample produces a recovery note.
main.gd
extends Control
const Lab = preload("res://release_lab.gd")
const TITLE = "Update without losing flight progress"
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_flights":2}'
const NEW_SAVE := '{"schema":2,"completed":3,"sound":false}'
const DAMAGED_SAVE := '["completed", "two"]'
func build() -> void:
ui.say("Try three fictional JSON records. The lab never overwrites a real save.")
ui.option("Old-save example", show_migration.bind(OLD_SAVE))
ui.option("New-save example", show_migration.bind(NEW_SAVE))
ui.option("Damaged-save example", show_migration.bind(DAMAGED_SAVE))
func show_migration(raw: String) -> void:
var result := migrate(raw)
if result.is_empty():
ui.say("This record cannot be read by the lab. Preserve the source and offer recovery.")
else:
ui.say("Schema %d. Completed flights: %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", 0)
if not (schema is float or schema is int) or not (schema == 1 or schema == 2):
return {}
match int(schema):
1:
if not data.has("completed_flights"):
return {}
return {"schema": 2, "completed": clampi(int(data.completed_flights), 0, 9), "sound": true}
2:
if not data.has("completed") or not (data.get("sound") is bool):
return {}
return {"schema": 2, "completed": clampi(int(data.completed), 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("#14283d")
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("#ffd293"))
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 = "Update without losing flight progress"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_flights":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 DAMAGED_SAVE := '["completed", "two"]'Creates a constant named DAMAGED_SAVE. 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("Try three fictional JSON records. The lab never overwrites a real save.")Calls ui.say with the values in its parentheses. -
ui.option("Old-save example", show_migration.bind(OLD_SAVE))Calls ui.option with the values in its parentheses. -
ui.option("New-save example", show_migration.bind(NEW_SAVE))Calls ui.option with the values in its parentheses. -
ui.option("Damaged-save example", show_migration.bind(DAMAGED_SAVE))Calls ui.option with the values in its parentheses. -
func show_migration(raw: String) -> void:Defines show migration, 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("This record cannot be read by the lab. Preserve 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 flights: %d. Sound: %s." % [result.schema, result.completed, "on" if result.sound else "off"])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 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", 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 not (schema is float or schema is int) or not (schema == 1 or schema == 2):Checks not (schema is float or schema is int) or not (schema == 1 or 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. -
if not data.has("completed_flights"):Checks not data.has("completed_flights"). 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(data.completed_flights), 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. -
if not data.has("completed") or not (data.get("sound") is bool):Checks not data.has("completed") 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(data.completed), 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("#14283d")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("#ffd293"))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 new-format record loses the sound preference, confirm the save contains the Boolean false, without quotation marks, and the code reads the sound field.
Try a change
Ages 10–12. Record before-and-after results for all three buttons. Ages 13–16. Add a separate fixture for a future schema and a recovery choice that preserves the source.