Cabin Crew Express · Lesson 24 of 50 · Intermediate · About 25 min
Before regular service starts, Ari needs to bring a meal to 3D. A water order at 1A will stay open until that job is done.

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/23 when the lesson builds on prior work, or copy the checkpoints/24 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 priority, String, and, not, membership, early return.
-
Open the training cabin
Unzip the course project and open Godot 4.7.2. In Project Manager choose Import, select the project.godot file inside checkpoints/24, then choose Edit. Click the Run Project triangle at the top right or press F5.
Why it works A fresh checkpoint opens the exact version for this lesson. Make a copy before changing any code so you can compare the result.
-
Spot the priority seat
Open mission.json and locate priority. Follow that key to the requests dictionary and confirm what the same seat needs.
"priority": "3D"Why it works One seat ID can refer to a request in more than one rule. Keeping the item in the requests dictionary avoids recording it twice.
-
Read the three conditions
Double-click cabin_rules.gd. Locate the priority guard in the serve branch. Read each of the three conditions in order as a yes-or-no question.
if priority != "" and seat_id != priority and not state["served"].has(priority):Why it works The return runs only when a priority seat exists, the selected seat is different, and the priority seat has not been served.
-
Find the proper place for the check
Trace the serve branch from the row check through to erase and append. Use the status below the board to see whether you tested the row, the priority or whether Ari has the item.
state["served"].append(seat_id)Why it works Early checks explain rejected moves before any stock is spent. erase and append only run after a valid delivery.
-
Try to serve 1A early
From the galley load Water and Meal, move to row 1, then click 1A. The priority message should name 3D and both items should remain in the cart.
Why it works The gate is based on the delivery status, so arriving first does not cancel the higher-priority order.
-
Serve first, then come back
Move to row 3 and give the meal to 3D. Come back to row 1 and hand over the water. Watch the completed labels until the final message appears.
Why it works Serving the priority seat adds its ID to the served array. The same gate now allows the standard request.
Watch the values change
-
Try seat 1A first Priority seat 3D open, both items loaded
What you see. The water stays in the cart. -
Serve 3D on row 3 3D in the served array
What you see. The priority gate unlocks. -
Return to row 1 and serve 1A Both IDs served
What you see. The cabin is ready.
Predict before you run What happens to standard service if priority is an empty string?
Reveal the answer
The first condition is false, so standard deliveries are allowed whenever the other checks pass.
Complete checkpoint
The non-priority seat is blocked until the priority request is delivered. Both remain independently visible.
main.gd
extends Control
const Rules = preload("res://cabin_rules.gd")
const SEATS = ["A", "B", "C", "D"]
var mission: Dictionary
var state: Dictionary
var status: Label
var manifest: Label
var summary: Label
var seats: Dictionary = {}
var stripe: ColorRect
func _ready() -> void:
make_panel(Color("#14283f"), Rect2(0, 0, 960, 540))
make_label("CABIN CREW EXPRESS", Rect2(28, 18, 450, 36), 27)
make_label("TRAINING FLIGHT • CHECKPOINT 24", Rect2(29, 57, 510, 27), 14)
mission = Rules.load_mission()
if mission.is_empty():
make_label("Could not read mission.json. Check its braces and commas.", Rect2(28, 140, 880, 50), 22)
return
state = Rules.initial_state(mission)
make_panel(Color("#203a53"), Rect2(28, 98, 522, 332))
make_panel(Color("#203a53"), Rect2(568, 98, 364, 332))
make_label("Galley", Rect2(254, 111, 90, 35), 16)
var row_stripe := make_panel(Color("#52728a"), Rect2(256, 150, 67, 245))
row_stripe.mouse_filter = Control.MOUSE_FILTER_IGNORE
stripe = make_panel(Color("#ffd386"), Rect2(258, 158, 63, 18))
stripe.mouse_filter = Control.MOUSE_FILTER_IGNORE
var lefts := [46, 150, 335, 439]
for row in range(1, int(mission["rows"]) + 1):
var top := 157 + row * 65
make_label(str(row), Rect2(276, top, 28, 42), 19)
for col in range(SEATS.size()):
var seat_id := str(row) + str(SEATS[col])
var button := make_button(seat_id, Rect2(lefts[col], top, 92, 42), "serve:" + seat_id)
seats[seat_id] = button
make_label("Galley supplies", Rect2(585, 111, 310, 25), 19)
for slot in range(Rules.SUPPLIES.size()):
var item: String = Rules.SUPPLIES[slot]
make_button(item, Rect2(585 + slot * 108, 146, 100, 39), "load:" + item)
var up := make_button("Earlier row", Rect2(585, 201, 100, 40), "up")
make_button("Later row", Rect2(693, 201, 100, 40), "down")
make_button("Restart", Rect2(801, 201, 100, 40), "reset")
manifest = make_label("", Rect2(585, 314, 305, 105), 15)
summary = make_label("", Rect2(29, 438, 900, 30), 19)
status = make_label("", Rect2(29, 477, 900, 56), 17)
status.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
up.grab_focus()
refresh("Train as Ari. Load items at the galley, then choose seats from the aisle.")
func make_panel(shade: Color, box: Rect2) -> ColorRect:
var card := ColorRect.new()
card.color = shade
card.position = box.position
card.size = box.size
add_child(card)
return card
func make_label(copy: String, box: Rect2, font_size: int) -> Label:
var label := Label.new()
label.text = copy
label.position = box.position
label.size = box.size
label.add_theme_font_size_override("font_size", font_size)
add_child(label)
return label
func make_button(copy: String, box: Rect2, action: String) -> Button:
var button := Button.new()
button.text = copy
button.position = box.position
button.size = box.size
button.add_theme_font_size_override("font_size", 14)
button.pressed.connect(command.bind(action))
add_child(button)
return button
func _input(event: InputEvent) -> void:
if mission.is_empty() or not (event is InputEventKey) or not event.pressed or event.echo:
return
if event.keycode == KEY_UP or event.keycode == KEY_DOWN:
command("up" if event.keycode == KEY_UP else "down")
get_viewport().set_input_as_handled()
func command(action: String) -> void:
if action == "reset":
state = Rules.initial_state(mission)
refresh("Cabin restarted. Check the manifest before your first move.")
return
var result := Rules.apply_action(mission, state, action)
refresh(result["message"])
func refresh(message: String) -> void:
stripe.position.y = 129 + int(state["row"]) * 65
if state["row"] > 0:
stripe.position.y += 34
for seat_id in seats:
var button: Button = seats[seat_id]
var requested: String = mission["requests"].get(seat_id, "")
button.text = seat_id if requested == "" else "%s %s" % [seat_id, requested]
if state["served"].has(seat_id):
button.text = "%s done" % seat_id
var row_name := "Galley" if state["row"] == 0 else "Row %d" % state["row"]
var carry := ", ".join(state["cart"])
if carry == "":
carry = "empty"
var rows: Array[String] = []
for seat_id in mission["requests"]:
rows.append("%s asks for %s" % [seat_id, mission["requests"][seat_id]])
manifest.text = "
".join(rows)
if mission["priority"] != "":
manifest.text += "\nFirst service: " + mission["priority"]
summary.text = "%s • Cart: %s • %d/%d served • Turns: %d / %d" % [
row_name, carry, state["served"].size(), mission["requests"].size(), state["turns"], int(mission["budget"])]
status.text = message
cabin_rules.gd
extends RefCounted
const SUPPLIES = ["Water", "Meal", "Blanket"]
const CAPACITY = 2
static func load_mission() -> Dictionary:
var file := FileAccess.open("res://mission.json", FileAccess.READ)
if file == null:
return {}
var text := file.get_as_text()
var data: Variant = JSON.parse_string(text)
if not (data is Dictionary):
return {}
if not (data.get("requests") is Dictionary):
return {}
return data
static func seat_row(seat_id: String) -> int:
return seat_id.substr(0, seat_id.length() - 1).to_int()
static func initial_state(mission: Dictionary) -> Dictionary:
return {"row": 0, "cart": [], "served": [], "turns": 0, "clear": mission["blocked_row"] < 0}
static func is_finished(mission: Dictionary, state: Dictionary) -> bool:
return state["served"].size() == mission["requests"].size()
static func apply_action(mission: Dictionary, state: Dictionary, action: String) -> Dictionary:
if is_finished(mission, state):
return {"accepted": false, "message": "Service is already complete."}
if state["turns"] >= int(mission["budget"]):
return {"accepted": false, "message": "Turn budget used. Restart and plan a shorter route."}
var message := ""
if action == "up" or action == "down":
var step := -1 if action == "up" else 1
var destination: int = state["row"] + step
if destination < 0 or destination > int(mission["rows"]):
return {"accepted": false, "message": "This is the end of the aisle."}
state["row"] = destination
message = "At the galley." if destination == 0 else "Ari reached row %d." % destination
elif action.begins_with("load:"):
if state["row"] != 0:
return {"accepted": false, "message": "Return to the galley to load supplies."}
if state["cart"].size() >= CAPACITY:
return {"accepted": false, "message": "The cart already holds two items."}
var item := action.get_slice(":", 1)
if not SUPPLIES.has(item):
return {"accepted": false, "message": "That item is not stocked."}
state["cart"].append(item)
message = "Loaded %s." % item
elif action.begins_with("serve:"):
var seat_id := action.get_slice(":", 1)
var requests: Dictionary = mission["requests"]
if not requests.has(seat_id) or state["served"].has(seat_id):
return {"accepted": false, "message": "There is no open request at %s." % seat_id}
if seat_row(seat_id) != state["row"]:
return {"accepted": false, "message": "Move beside row %d first." % seat_row(seat_id)}
var priority: String = mission["priority"]
if priority != "" and seat_id != priority and not state["served"].has(priority):
return {"accepted": false, "message": "Serve priority seat %s before the other requests." % priority}
var item: String = requests[seat_id]
if not state["cart"].has(item):
return {"accepted": false, "message": "%s needs %s. Check your cart." % [seat_id, item]}
state["cart"].erase(item)
state["served"].append(seat_id)
message = "Delivered %s to %s." % [item, seat_id]
else:
return {"accepted": false, "message": "Choose a service action."}
state["turns"] += 1
if is_finished(mission, state):
message += " Cabin ready!"
return {"accepted": true, "message": message, "state": state}
mission.json
{
"rows": 3,
"budget": 12,
"blocked_row": -1,
"requests": {
"1A": "Water",
"3D": "Meal"
},
"priority": "3D"
}
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 ControlMake the scene a Godot Control so it can hold and position interface nodes. -
const Rules = preload("res://cabin_rules.gd")Load the script that contains the cabin rules when this scene is parsed. -
const SEATS = ["A", "B", "C", "D"]Give the four seat columns letter names. A and B sit left of the aisle, while C and D sit right. -
var mission: DictionaryKeep the layout and request manifest separate from the state created while playing. -
var state: DictionaryStore changes to position, turn count, supplies, delivery flags and the obstruction. -
var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here. -
var manifest: LabelDeclares manifest for later use. A colon followed by a type says which kind of value belongs here. -
var summary: LabelDeclares summary for later use. A colon followed by a type says which kind of value belongs here. -
var seats: Dictionary = {}Creates a variable named seats. The expression makes a dictionary that looks up values by key. The type after the colon says what kind of value it can hold. -
var stripe: ColorRectDeclares stripe 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. -
make_panel(Color("#14283f"), Rect2(0, 0, 960, 540))Calls make_panel with the values in its parentheses. -
make_label("CABIN CREW EXPRESS", Rect2(28, 18, 450, 36), 27)Calls make_label with the values in its parentheses. -
make_label("TRAINING FLIGHT • CHECKPOINT 24", Rect2(29, 57, 510, 27), 14)Calls make_label with the values in its parentheses. -
mission = Rules.load_mission()Read all training flight data before creating any seat buttons. -
if mission.is_empty():Show a tiny error screen if the manifest could not be loaded or did not pass the data guards. -
make_label("Could not read mission.json. Check its braces and commas.", Rect2(28, 140, 880, 50), 22)Calls make_label with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
state = Rules.initial_state(mission)Give this play session a fresh copy of the starting state. -
make_panel(Color("#203a53"), Rect2(28, 98, 522, 332))Calls make_panel with the values in its parentheses. -
make_panel(Color("#203a53"), Rect2(568, 98, 364, 332))Calls make_panel with the values in its parentheses. -
make_label("Galley", Rect2(254, 111, 90, 35), 16)Calls make_label with the values in its parentheses. -
var row_stripe := make_panel(Color("#52728a"), Rect2(256, 150, 67, 245))Creates a variable named row_stripe. The expression calls make_panel with the values in its parentheses. Godot infers the type from the first value. -
row_stripe.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates row_stripe.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
stripe = make_panel(Color("#ffd386"), Rect2(258, 158, 63, 18))Stores the new value in stripe. The expression calls make_panel with the values in its parentheses. -
stripe.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates stripe.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
var lefts := [46, 150, 335, 439]Leave space after the second seat for the aisle between the two sides. -
for row in range(1, int(mission["rows"]) + 1):Make one row per passenger row. range excludes its upper bound, so add one to include the last row. -
var top := 157 + row * 65Creates a variable named top. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value. -
make_label(str(row), Rect2(276, top, 28, 42), 19)Calls make_label with the values in its parentheses. -
for col in range(SEATS.size()):Repeats the indented instructions for each value in range(SEATS.size()). -
var seat_id := str(row) + str(SEATS[col])Join row number and column name to form a stable passenger ID such as 2A. -
var button := make_button(seat_id, Rect2(lefts[col], top, 92, 42), "serve:" + seat_id)Creates a variable named button. The expression calls make_button with the values in its parentheses. Godot infers the type from the first value. -
seats[seat_id] = buttonIndex a button by seat name so refresh can later change its label independently. -
make_label("Galley supplies", Rect2(585, 111, 310, 25), 19)Calls make_label with the values in its parentheses. -
for slot in range(Rules.SUPPLIES.size()):Repeats the indented instructions for each value in range(Rules.SUPPLIES.size()). -
var item: String = Rules.SUPPLIES[slot]Read each stock label from the list used by the rules so button names and commands agree. -
make_button(item, Rect2(585 + slot * 108, 146, 100, 39), "load:" + item)Calls make_button with the values in its parentheses. -
var up := make_button("Earlier row", Rect2(585, 201, 100, 40), "up")Creates a variable named up. The expression calls make_button with the values in its parentheses. Godot infers the type from the first value. -
make_button("Later row", Rect2(693, 201, 100, 40), "down")Calls make_button with the values in its parentheses. -
make_button("Restart", Rect2(801, 201, 100, 40), "reset")Calls make_button with the values in its parentheses. -
manifest = make_label("", Rect2(585, 314, 305, 105), 15)Stores the new value in manifest. The expression calls make_label with the values in its parentheses. -
summary = make_label("", Rect2(29, 438, 900, 30), 19)Stores the new value in summary. The expression calls make_label with the values in its parentheses. -
status = make_label("", Rect2(29, 477, 900, 56), 17)Stores the new value in status. The expression calls make_label with the values in its parentheses. -
status.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTAllow a long message to wrap without hiding the end of it. -
up.grab_focus()Make the first navigation button ready for keyboard input. -
refresh("Train as Ari. Load items at the galley, then choose seats from the aisle.")Calls refresh with the values in its parentheses. -
func make_panel(shade: Color, box: Rect2) -> ColorRect:Defines make panel, 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 card := ColorRect.new()Creates a variable named card. The expression creates a new ColorRect object. Godot infers the type from the first value. -
card.color = shadeStores the new value in card.color. The expression reads shade. -
card.position = box.positionUpdates card.position, which controls the node's local x and y location. The expression reads box.position. -
card.size = box.sizeUpdates card.size, which controls the control's width and height. The expression reads box.size. -
add_child(card)Adds the new node to the scene tree so that Godot can run and draw it. -
return cardFinishes the function and hands its result back to the caller. The expression reads card. -
func make_label(copy: String, box: Rect2, font_size: int) -> Label:Defines make label, 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 label := Label.new()Creates a variable named label. The expression creates a new Label object. Godot infers the type from the first value. -
label.text = copyUpdates label.text, which controls the words a player sees. The expression reads copy. -
label.position = box.positionUpdates label.position, which controls the node's local x and y location. The expression reads box.position. -
label.size = box.sizeUpdates label.size, which controls the control's width and height. The expression reads box.size. -
label.add_theme_font_size_override("font_size", font_size)Calls label.add_theme_font_size_override with the values in its parentheses. -
add_child(label)Adds the new node to the scene tree so that Godot can run and draw it. -
return labelFinishes the function and hands its result back to the caller. The expression reads label. -
func make_button(copy: String, box: Rect2, action: String) -> Button:Defines make 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 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 = copyUpdates button.text, which controls the words a player sees. The expression reads copy. -
button.position = box.positionUpdates button.position, which controls the node's local x and y location. The expression reads box.position. -
button.size = box.sizeUpdates button.size, which controls the control's width and height. The expression reads box.size. -
button.add_theme_font_size_override("font_size", 14)Calls button.add_theme_font_size_override with the values in its parentheses. -
button.pressed.connect(command.bind(action))Send the right command string into command when a passenger or galley button is pressed. -
add_child(button)Adds the new node to the scene tree so that Godot can run and draw it. -
return buttonFinishes the function and hands its result back to the caller. The expression reads button. -
func _input(event: InputEvent) -> void:Godot calls this when input arrives. The event tells the game which key, pointer or touch action happened. -
if mission.is_empty() or not (event is InputEventKey) or not event.pressed or event.echo:Checks mission.is_empty() or not (event is InputEventKey) or not event.pressed or event.echo. The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
if event.keycode == KEY_UP or event.keycode == KEY_DOWN:Checks event.keycode == KEY_UP or event.keycode == KEY_DOWN. The indented instructions below run only if this test passes. -
command("up" if event.keycode == KEY_UP else "down")Calls command with the values in its parentheses. -
get_viewport().set_input_as_handled()Stop the same key from going to the keyboard focus system after the game has processed it. -
func command(action: String) -> void:Defines command, 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 action == "reset":Treat restarting as a special command rather than spending a regular service turn. -
state = Rules.initial_state(mission)Give this play session a fresh copy of the starting state. -
refresh("Cabin restarted. Check the manifest before your first move.")Calls refresh with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var result := Rules.apply_action(mission, state, action)Send a real command to the rules and wait for its result. -
refresh(result["message"])Calls refresh with the values in its parentheses. -
func refresh(message: String) -> void:Defines refresh, 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. -
stripe.position.y = 129 + int(state["row"]) * 65Move the visible gold aisle marker to the active row, starting at the galley. -
if state["row"] > 0:Checks state["row"] > 0. The indented instructions below run only if this test passes. -
stripe.position.y += 34Reads stripe.position.y, adds to its old value, then stores the result back in the same place. -
for seat_id in seats:Repeats the indented instructions for each value in seats. -
var button: Button = seats[seat_id]Creates a variable named button. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var requested: String = mission["requests"].get(seat_id, "")Read the label for an open order. Seats with no order can use an empty description. -
button.text = seat_id if requested == "" else "%s %s" % [seat_id, requested]Updates button.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle. -
if state["served"].has(seat_id):Checks state["served"].has(seat_id). The indented instructions below run only if this test passes. -
button.text = "%s done" % seat_idKeep the passenger’s seat ID visible while marking the delivered order in words. -
var row_name := "Galley" if state["row"] == 0 else "Row %d" % state["row"]Creates a variable named row_name. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
var carry := ", ".join(state["cart"])Make the cart summary readable by adding a comma between every packed item. -
if carry == "":Checks carry == "". The indented instructions below run only if this test passes. -
carry = "empty"Stores the new value in carry. The expression uses the text inside the quotes. -
var rows: Array[String] = []Creates a variable named rows. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
for seat_id in mission["requests"]:Repeats the indented instructions for each value in mission["requests"]. -
rows.append("%s asks for %s" % [seat_id, mission["requests"][seat_id]])Adds an item to the end of a list. -
manifest.text = "Updates manifest.text, which controls the words a player sees. The expression uses the text inside the quotes. -
".join(rows)Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
if mission["priority"] != "":Checks mission["priority"] != "". The indented instructions below run only if this test passes. -
manifest.text += "\nFirst service: " + mission["priority"]Reads manifest.text, adds to its old value, then stores the result back in the same place. -
summary.text = "%s • Cart: %s • %d/%d served • Turns: %d / %d" % [Updates summary.text, which controls the words a player sees. The expression uses the text inside the quotes. -
row_name, carry, state["served"].size(), mission["requests"].size(), state["turns"], int(mission["budget"])]Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
status.text = messageReplace previous feedback with the newest result or route hint.
Read cabin_rules.gd line by line
-
extends RefCountedCreate a script that stores rules without needing a node on the screen. RefCounted lets Godot free objects when nothing uses them. -
const SUPPLIES = ["Water", "Meal", "Blanket"]Keep the three stocked items together in a constant list. The galley buttons and load rule use the same names. -
const CAPACITY = 2Name the two-slot limit so a different part of the program does not quietly use another number. -
static func load_mission() -> Dictionary:Read the fixed rules for this training cabin. A static function can be called on the Rules script directly. -
var file := FileAccess.open("res://mission.json", FileAccess.READ)Open mission.json at the project root in reading mode. If the file is missing, file will be null. -
if file == null:Ask whether the manifest opened correctly before trying to read from it. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var text := file.get_as_text()Read the characters from the open file. At this point the contents are still raw text. -
var data: Variant = JSON.parse_string(text)Turn the JSON text into a Godot value. Variant allows a valid object or the null value returned for invalid text. -
if not (data is Dictionary):Reject a manifest whose outer value is not an object with named keys. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
if not (data.get("requests") is Dictionary):Require a dictionary of requests so each whole seat ID can act as a key. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
return dataHand the loaded configuration back to the caller. -
static func seat_row(seat_id: String) -> int:Accept the whole seat name and return just its numeric row. Keep the letter for looking up the request. -
return seat_id.substr(0, seat_id.length() - 1).to_int()Remove the last character and convert what remains. For 2D this produces 2, and for 12A it produces 12. -
static func initial_state(mission: Dictionary) -> Dictionary:Create fresh values for the live cabin. The mission defines the fixed layout, not which service actions have already happened. -
return {"row": 0, "cart": [], "served": [], "turns": 0, "clear": mission["blocked_row"] < 0}Start at the galley with no supplies, no delivered orders and no turns. A negative blocked-row index means the aisle is already clear. -
static func is_finished(mission: Dictionary, state: Dictionary) -> bool:Defines is finished, 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 state["served"].size() == mission["requests"].size()Complete the cabin when the served count equals the manifest’s request count. The service branch prevents duplicates in served. -
static func apply_action(mission: Dictionary, state: Dictionary, action: String) -> Dictionary:Defines apply action, 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 is_finished(mission, state):Checks is_finished(mission, state). The indented instructions below run only if this test passes. -
return {"accepted": false, "message": "Service is already complete."}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
if state["turns"] >= int(mission["budget"]):Check the cutoff before movement, loading or handoff. At the limit no more successful turns are available. -
return {"accepted": false, "message": "Turn budget used. Restart and plan a shorter route."}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var message := ""Creates a variable named message. The expression uses the text inside the quotes. Godot infers the type from the first value. -
if action == "up" or action == "down":Checks action == "up" or action == "down". The indented instructions below run only if this test passes. -
var step := -1 if action == "up" else 1Turn the movement command into one numerical step. Earlier rows use minus one, and later rows use plus one. -
var destination: int = state["row"] + stepCompute the proposed row without changing Ari’s current row. -
if destination < 0 or destination > int(mission["rows"]):Reject a move before the galley or beyond the last passenger row. -
return {"accepted": false, "message": "This is the end of the aisle."}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
state["row"] = destinationCommit this row in the working state after the aisle checks accept it. -
message = "At the galley." if destination == 0 else "Ari reached row %d." % destinationStores the new value in message. The expression chooses one of two values by checking the condition in the middle. -
elif action.begins_with("load:"):If the earlier branches did not run, checks action.begins_with("load:") next. -
if state["row"] != 0:The crew can load supplies only at the galley. -
return {"accepted": false, "message": "Return to the galley to load supplies."}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
if state["cart"].size() >= CAPACITY:Count both item slots. A repeated supply still occupies an additional slot. -
return {"accepted": false, "message": "The cart already holds two items."}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var item := action.get_slice(":", 1)Read the part after load: as the requested item name. load:Water uses Water. -
if not SUPPLIES.has(item):Checks not SUPPLIES.has(item). The indented instructions below run only if this test passes. -
return {"accepted": false, "message": "That item is not stocked."}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
state["cart"].append(item)Put the newly loaded item into one cart slot. -
message = "Loaded %s." % itemStores the new value in message. The expression uses the text inside the quotes. -
elif action.begins_with("serve:"):If the earlier branches did not run, checks action.begins_with("serve:") next. -
var seat_id := action.get_slice(":", 1)Extract the full passenger ID. serve:2D uses 2D, not just the row or letter. -
var requests: Dictionary = mission["requests"]Creates a variable named requests. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
if not requests.has(seat_id) or state["served"].has(seat_id):Reject a seat without a request or one that has already received its item. -
return {"accepted": false, "message": "There is no open request at %s." % seat_id}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
if seat_row(seat_id) != state["row"]:Require Ari to stand in the matching aisle row before handing anything over. -
return {"accepted": false, "message": "Move beside row %d first." % seat_row(seat_id)}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var priority: String = mission["priority"]Creates a variable named priority. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
if priority != "" and seat_id != priority and not state["served"].has(priority):Hold a standard order back while a named priority passenger is still waiting. -
return {"accepted": false, "message": "Serve priority seat %s before the other requests." % priority}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var item: String = requests[seat_id]Read the correct item using the full seat ID. -
if not state["cart"].has(item):Only a cart with the matching item can serve the passenger. -
return {"accepted": false, "message": "%s needs %s. Check your cart." % [seat_id, item]}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
state["cart"].erase(item)Remove one matching item from the cart after a valid delivery. If a second copy exists, it stays in the cart. -
state["served"].append(seat_id)Record exactly which passenger has been served. This can also release a priority gate. -
message = "Delivered %s to %s." % [item, seat_id]Stores the new value in message. The expression uses the text inside the quotes. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
return {"accepted": false, "message": "Choose a service action."}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
state["turns"] += 1Spend one turn at the shared successful exit. Paths that returned earlier leave this count alone. -
if is_finished(mission, state):Checks is_finished(mission, state). The indented instructions below run only if this test passes. -
message += " Cabin ready!"Reads message, adds to its old value, then stores the result back in the same place. -
return {"accepted": true, "message": message, "state": state}Send back the outcome, the message for the player and the working state the caller can keep.
mission.json holds data for the game. Curly braces group named values, square brackets make ordered lists and each colon connects a key to its value.
Find and fix a bug
If the priority seat rejects itself, look for the seat_id != priority comparison and make sure it is inside the and chain.
Try a change
Change priority to 1A and predict the fastest route before running it. Remember to keep a matching key in requests.