Cabin Crew Express · Lesson 20 of 50 · Beginner to intermediate · About 38 min
Ari is ready for a fresh attempt. Restart returns the same plane to its original state so another learner can repeat the service exercise.

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/19 when the lesson builds on prior work, or copy the checkpoints/20 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 clear(), reset function, button handler, acceptance tests, shared UI state, repeatable test.
-
Open the checkpoint in Godot
Extract the folder for lesson 20. In Godot Project Manager choose Import and select project.godot. Open the main scene in the FileSystem dock and select its Control root. Double-click main.gd to enter Script. Press F5 to run. The right panel now includes Serve, Undo and Restart.
extends ControlWhy it works Godot loads the Control scene and calls _ready after the node enters the scene tree. Press F8 to stop before making changes.
-
Connect the button to one reset function
Find the Restart button in _ready. Compare its last argument with _restart below.
_button("Restart", Vector2(782, 370), 103, _restart)Why it works The connected Callable is run on press. Keeping initial state changes in one function makes the whole restart visible in one place.
-
Restore the main cabin values
Load Water, move to row 2 and choose B. Tap Restart. Check the location, number of turns, selection and cart one by one.
cart.clear()Why it works row and turns are set back to their initial values. The empty string clears the selected guest and clear empties stock and delivered orders.
-
Clear past moves too
After the restart, tap Undo. Compare its message with the one from the previous lesson.
history.clear()Why it works Old snapshots belong to the previous attempt. Clearing history prevents an old load or delivery from returning after a reset.
-
Exercise the full tutorial route
Load Water and Meal, then serve 2B and 3C in order. Return, load Blanket and serve 6A. Return to the galley. Record the final turn total.
Why it works A complete check proves every subsystem works together. All accepted moves, loads and orders are counted, and previously blocked actions do not change the expected 24 turns.
-
Try restart after completion
At the completion caption press Restart, then press a direction key or tap Cabins. Verify row 1 and one turn.
finished = falseWhy it works Restart clears finished and resets the game. Both input paths still reach the same movement rule after a win.
Watch the values change
-
Load Water, move and select B. The cart, row, turns and selection all contain changes.
What you see. The cabin is midway through service. -
Restart and tap Undo. row is 0, turns is 0, both lists are empty, and history is empty.
What you see. The message reports Nothing to undo. -
Finish the full route and restart. finished returns to false and the new attempt accepts input.
What you see. The cabin is ready for another trainee.
Predict before you run What would happen if Restart cleared the cart but left finished true?
Reveal the answer
The completed-state guards would still refuse movement and loading. Reset must clear the flag with the rest of the state.
Complete checkpoint
A complete 24-turn shift can restart directly into an empty galley, with no old history and fully enabled controls.
main.gd
extends Control
const ROW_COUNT := 6
const TOP_ROW_Y := 153
const ROW_GAP := 38
const SEAT_LETTERS: Array[String] = ["A", "B", "C", "D"]
const SEAT_X: Array[int] = [49, 126, 276, 353]
const INK := Color("#162d43")
const PANEL := Color("#1c4057")
const PAPER := Color("#f4f1e4")
const MINT := Color("#83dbba")
const GOLD := Color("#ffd986")
var row := 0
var status := "Welcome aboard. Move towards the cabins."
var location_label: Label
var note_label: Label
var turns := 0
const GALLEY := 0
var cart: Array[String] = []
const CAPACITY := 2
const ORDERS := {"2B": "Water", "3C": "Meal", "6A": "Blanket"}
var selected := ""
var delivered: Array[String] = []
var finished := false
var history: Array[Dictionary] = []
func _ready() -> void:
_text("CABIN CREW EXPRESS", Vector2(30, 21), Vector2(580, 34), 27)
_text("Ari’s cabin service training", Vector2(31, 59), Vector2(580, 22), 15)
_text("SINGLE AISLE · CABIN PLAN", Vector2(48, 106), Vector2(340, 24), 14)
location_label = _text("", Vector2(469, 112), Vector2(437, 30), 20)
_button("← Galley", Vector2(469, 147), 196, _try_move.bind(-1))
_button("Cabins →", Vector2(687, 147), 196, _try_move.bind(1))
note_label = _text("", Vector2(469, 444), Vector2(438, 60), 17)
note_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
_text("GALLEY SUPPLIES · LOAD ONLY AT ROW 0", Vector2(469, 198), Vector2(435, 23), 13)
_button("Water", Vector2(469, 225), 133, _load_item.bind("Water"))
_button("Meal", Vector2(610, 225), 133, _load_item.bind("Meal"))
_button("Blanket", Vector2(751, 225), 133, _load_item.bind("Blanket"))
_text("CHOOSE A SEAT IN THIS ROW", Vector2(469, 283), Vector2(435, 23), 13)
for index in range(SEAT_LETTERS.size()):
var letter := SEAT_LETTERS[index]
_button("Seat " + letter, Vector2(469 + index * 105, 313), 97, _select_seat.bind(letter))
_button("Serve selected order", Vector2(469, 370), 196, _serve)
_button("Undo", Vector2(674, 370), 100, _undo)
_button("Restart", Vector2(782, 370), 103, _restart)
_refresh()
func _text(words: String, at: Vector2, box: Vector2, font_size: int) -> Label:
var label := Label.new()
label.text = words
label.position = at
label.size = box
label.add_theme_font_size_override("font_size", font_size)
label.add_theme_color_override("font_color", PAPER)
add_child(label)
return label
func _button(words: String, at: Vector2, width: int, handler: Callable) -> void:
var button := Button.new()
button.text = words
button.position = at
button.custom_minimum_size = Vector2(width, 44)
button.size = Vector2(width, 44)
button.pressed.connect(handler)
add_child(button)
func _unhandled_key_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left"):
_try_move(-1)
elif event.is_action_pressed("ui_down") or event.is_action_pressed("ui_right"):
_try_move(1)
func _try_move(direction: int) -> void:
if finished:
_report("Shift complete. The cabin is ready.")
return
var candidate := row + direction
if candidate < 0 or candidate > ROW_COUNT:
_report("End of the aisle. Ari stays here.")
return
_remember()
row = candidate
turns += 1
selected = ""
if row == GALLEY and delivered.size() == ORDERS.size():
finished = true
_report("Shift complete. All three guests served!")
return
_report("Ari reached " + _place_name() + ".")
func _load_item(item: String) -> void:
if finished:
_report("Shift complete. The cabin is ready.")
return
if row != GALLEY:
_report("Go back to the galley to load supplies.")
return
if cart.size() >= CAPACITY:
_report("Cart full. Two items fit.")
return
_remember()
cart.append(item)
turns += 1
_report(item + " loaded.")
func _select_seat(letter: String) -> void:
var seat := str(row) + letter
if not ORDERS.has(seat):
selected = ""
_report(seat + " has no request.")
return
selected = seat
if delivered.has(seat):
_report(seat + " has already been served.")
return
_report(seat + " requests " + str(ORDERS[seat]) + ".")
func _serve() -> void:
if finished:
_report("Shift complete. The cabin is ready.")
return
if selected.is_empty():
_report("Select a passenger in this row first.")
return
if delivered.has(selected):
_report(selected + " has already been served.")
return
var item: String = ORDERS[selected]
var slot := cart.find(item)
if slot == -1:
_report("Need " + item + " for " + selected + ".")
return
_remember()
cart.remove_at(slot)
delivered.append(selected)
turns += 1
_report("Delivered " + item + " to " + selected + ".")
if delivered.size() == ORDERS.size():
_report("All guests served. Walk back to the galley.")
func _remember() -> void:
history.append({
"row": row, "turns": turns, "selected": selected,
"cart": cart.duplicate(), "delivered": delivered.duplicate(), "finished": finished
})
func _undo() -> void:
if history.is_empty():
_report("Nothing to undo.")
return
var previous: Dictionary = history.pop_back()
row = previous["row"]
turns = previous["turns"]
selected = previous["selected"]
cart.assign(previous["cart"])
delivered.assign(previous["delivered"])
finished = previous["finished"]
_report("Last action undone.")
func _restart() -> void:
row = GALLEY
turns = 0
selected = ""
cart.clear()
delivered.clear()
finished = false
history.clear()
_report("New shift. Load the cart at the galley.")
func _place_name() -> String:
if row == 0:
return "the galley"
return "row " + str(row)
func _report(words: String) -> void:
status = words
_refresh()
func _refresh() -> void:
location_label.text = "Ari is at " + _place_name().capitalize()
location_label.text += " · %d turns" % turns
note_label.text = status
note_label.text += "\nCart: " + ("empty" if cart.is_empty() else ", ".join(cart))
if finished:
location_label.text = "Shift complete · %d turns" % turns
queue_redraw()
func _draw() -> void:
var font := ThemeDB.fallback_font
draw_rect(Rect2(0, 0, 960, 540), INK)
draw_rect(Rect2(29, 92, 388, 414), PANEL)
draw_rect(Rect2(438, 92, 492, 414), PANEL)
draw_rect(Rect2(193, 126, 54, 256), Color("#132b3d"))
draw_string(font, Vector2(139, 137), "GALLEY", HORIZONTAL_ALIGNMENT_LEFT, -1, 13, GOLD)
for y in range(1, ROW_COUNT + 1):
var seat_y := TOP_ROW_Y + (y - 1) * ROW_GAP
for index in range(SEAT_LETTERS.size()):
var x := SEAT_X[index]
var letter := SEAT_LETTERS[index]
var seat := str(y) + letter
var seat_colour := Color("#315b70")
if ORDERS.has(seat):
seat_colour = Color("#825b3a")
if delivered.has(seat):
seat_colour = Color("#366a59")
draw_rect(Rect2(x, seat_y, 49, 31), seat_colour)
draw_string(font, Vector2(x + 10, seat_y + 21), seat, HORIZONTAL_ALIGNMENT_LEFT, -1, 15, PAPER)
if seat == selected:
draw_rect(Rect2(x - 2, seat_y - 2, 53, 35), GOLD, false, 2.0)
var ari_y := 140 if row == 0 else TOP_ROW_Y + 15 + (row - 1) * ROW_GAP
draw_circle(Vector2(220, ari_y), 11, MINT)
draw_string(font, Vector2(210, ari_y + 3), "ARI", HORIZONTAL_ALIGNMENT_LEFT, -1, 10, INK)
var order_line := "2B · Water 3C · Meal 6A · Blanket"
draw_string(font, Vector2(47, 401), order_line, HORIZONTAL_ALIGNMENT_LEFT, -1, 15, GOLD)
var progress := "%d / %d served" % [delivered.size(), ORDERS.size()]
draw_string(font, Vector2(47, 438), progress, HORIZONTAL_ALIGNMENT_LEFT, -1, 18, MINT)
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 ControlThe lesson’s root is a Godot Control. This base supplies screen drawing and lets the script add labels and interactive buttons to the same scene. -
const ROW_COUNT := 6Name the highest permitted aisle row. Passenger rows run from 1 to 6. The galley at 0 is a separate legal place. -
const TOP_ROW_Y := 153Begin the first row of seats at y = 153 pixels in the teaching viewport. -
const ROW_GAP := 38Place each next passenger row 38 pixels below the preceding one. -
const SEAT_LETTERS: Array[String] = ["A", "B", "C", "D"]Keep A and B on the left side and C and D on the right. The seat-letter loop uses this order. -
const SEAT_X: Array[int] = [49, 126, 276, 353]Store one x pixel position for each seat letter in the same index order. The wide gap between the second and third values forms the aisle. -
const INK := Color("#162d43")Creates a constant named INK. The expression builds a colour from these values. Godot infers the type from the first value. -
const PANEL := Color("#1c4057")Creates a constant named PANEL. The expression builds a colour from these values. Godot infers the type from the first value. -
const PAPER := Color("#f4f1e4")Creates a constant named PAPER. The expression builds a colour from these values. Godot infers the type from the first value. -
const MINT := Color("#83dbba")Creates a constant named MINT. The expression builds a colour from these values. Godot infers the type from the first value. -
const GOLD := Color("#ffd986")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value. -
var row := 0Start Ari in the galley. The row is a game position, independent of the number of pixels used to draw it. -
var status := "Welcome aboard. Move towards the cabins."Keep the latest player message in a value that other functions can update. -
var location_label: LabelReserve a typed reference for the Label that will show Ari’s row and accepted turn count. -
var note_label: LabelReserve a Label for action feedback and the live cart inventory. -
var turns := 0Start with no accepted actions. Walking, loading and serving will add to this counter only after their checks pass. -
const GALLEY := 0Give the special position 0 a familiar name. The stock and finish rules use the same named location. -
var cart: Array[String] = []Create the list of supplies currently loaded. Each stored string occupies one position in the cart. -
const CAPACITY := 2Limit usable cart positions to two so that planning which items to carry becomes part of the puzzle. -
const ORDERS := {"2B": "Water", "3C": "Meal", "6A": "Blanket"}Store three specific seat-to-supply pairs. The spelling of a lookup key must match a row followed by a letter. -
var selected := ""Start with the empty string. A successful seat choice will replace it with a complete ID such as 2B. -
var delivered: Array[String] = []Keep a record of the guests already served. Each entry is a seat ID, so different guests can request the same kind of supply. -
var finished := falseStart an active shift. true means the shift has met the service and return-to-galley requirements. -
var history: Array[Dictionary] = []Keep each earlier state as one dictionary. The newest entry at the end is the next action to undo. -
func _ready() -> void:Godot calls this once as the Control becomes ready. The function places the controls and starts the first display refresh. -
_text("CABIN CREW EXPRESS", Vector2(30, 21), Vector2(580, 34), 27)Calls _text with the values in its parentheses. -
_text("Ari’s cabin service training", Vector2(31, 59), Vector2(580, 22), 15)Calls _text with the values in its parentheses. -
_text("SINGLE AISLE · CABIN PLAN", Vector2(48, 106), Vector2(340, 24), 14)Calls _text with the values in its parentheses. -
location_label = _text("", Vector2(469, 112), Vector2(437, 30), 20)Create the main status header first and retain it for row and turn updates. -
_button("← Galley", Vector2(469, 147), 196, _try_move.bind(-1))The named Galley button sends -1 to the movement rule when pressed. Its screen arrow and placement point the player back. -
_button("Cabins →", Vector2(687, 147), 196, _try_move.bind(1))The Cabins button sends +1 towards the higher-numbered passenger rows. -
note_label = _text("", Vector2(469, 444), Vector2(438, 60), 17)Create the multiline feedback area below the service controls and keep a reference to it. -
note_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTAllow long reports to fit the right panel by breaking at word boundaries. -
_text("GALLEY SUPPLIES · LOAD ONLY AT ROW 0", Vector2(469, 198), Vector2(435, 23), 13)Calls _text with the values in its parentheses. -
_button("Water", Vector2(469, 225), 133, _load_item.bind("Water"))Make the Water button request its own supply with the shared galley rule. -
_button("Meal", Vector2(610, 225), 133, _load_item.bind("Meal"))Make this button send Meal to exactly the same loading function. -
_button("Blanket", Vector2(751, 225), 133, _load_item.bind("Blanket"))Connect the Blanket choice to the same location and cart checks as the other items. -
_text("CHOOSE A SEAT IN THIS ROW", Vector2(469, 283), Vector2(435, 23), 13)Calls _text with the values in its parentheses. -
for index in range(SEAT_LETTERS.size()):Run the body once for each letter index. The current function uses that index to create or draw every seat in order. -
var letter := SEAT_LETTERS[index]Read the seat letter from its original position in the four-element list. -
_button("Seat " + letter, Vector2(469 + index * 105, 313), 97, _select_seat.bind(letter))Place four controls horizontally. Bind a single letter so the rule can combine it with Ari’s row at the time of the press. -
_button("Serve selected order", Vector2(469, 370), 196, _serve)Connect the button with no extra parameter because _serve reads the current selection and cart. -
_button("Undo", Vector2(674, 370), 100, _undo)Make the newest accepted action reversible from the service panel. -
_button("Restart", Vector2(782, 370), 103, _restart)Offer a way to clear all training data and start a fresh service. -
_refresh()Calls _refresh with the values in its parentheses. -
func _text(words: String, at: Vector2, box: Vector2, font_size: int) -> Label:Collect the label setup into one helper. The caller supplies the displayed words, a position, a size and the desired font size. -
var label := Label.new()Create a Godot Label at runtime for the text UI. -
label.text = wordsGive the new label the words passed by its caller. -
label.position = atSet its top-left pixel location on the Control screen. -
label.size = boxSet the requested bounding rectangle so the text can wrap within the feedback region. -
label.add_theme_font_size_override("font_size", font_size)Apply this helper’s requested size to the Label without changing the global project theme. -
label.add_theme_color_override("font_color", PAPER)Use the shared warm-white text colour for readable interface labels. -
add_child(label)Attach the Label to the active scene tree so Godot will draw it. -
return labelProvide the newly created node to its caller so dynamic text can later be edited. -
func _button(words: String, at: Vector2, width: int, handler: Callable) -> void:Reuse one constructor for all touch-friendly buttons. A Callable carries the function to connect. -
var button := Button.new()Make a standard Godot Button that supports pointer input and keyboard focus. -
button.text = wordsUpdates button.text, which controls the words a player sees. The expression reads words. -
button.position = atUpdates button.position, which controls the node's local x and y location. The expression reads at. -
button.custom_minimum_size = Vector2(width, 44)Reserve at least 44 drawing pixels vertically for this checkpoint’s buttons. -
button.size = Vector2(width, 44)Updates button.size, which controls the control's width and height. The expression packs x and y into one value. -
button.pressed.connect(handler)Connect the press signal to the caller’s behaviour. Bound values such as a direction or stock item are kept on that callable. -
add_child(button)Put the Button in the running scene so it can appear and receive interaction. -
func _unhandled_key_input(event: InputEvent) -> void:Handle recognised arrow events after ordinary GUI controls have had their chance to respond. -
if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left"):Recognise either Up or Left as a move back towards row 0. -
_try_move(-1)Calls _try_move with the values in its parentheses. -
elif event.is_action_pressed("ui_down") or event.is_action_pressed("ui_right"):If the previous test was false, recognise Down or Right as a move towards the passenger rows. -
_try_move(1)Calls _try_move with the values in its parentheses. -
func _try_move(direction: int) -> void:All movement inputs ask this one function to propose and validate a step. -
if finished:Checks finished. The indented instructions below run only if this test passes. -
_report("Shift complete. The cabin is ready.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var candidate := row + directionAdd the move offset to the old row without altering Ari’s current position yet. -
if candidate < 0 or candidate > ROW_COUNT:Reject an invalid row if either comparison is true. Legal endpoints 0 and 6 both pass. -
_report("End of the aisle. Ari stays here.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
_remember()Calls _remember with the values in its parentheses. -
row = candidateCommit the new row only after both ends of the aisle have been checked. -
turns += 1Spend exactly one turn for this accepted action, after all refusal branches have returned. -
selected = ""Clear the current choice so the game cannot reuse a passenger from another row or after a reset. -
if row == GALLEY and delivered.size() == ORDERS.size():Complete the shift only when Ari is back at the galley and the delivered count matches the order count. -
finished = trueLock the completed state so new movement, stock and service presses cannot unexpectedly change the finishing total. -
_report("Shift complete. All three guests served!")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
_report("Ari reached " + _place_name() + ".")Calls _report with the values in its parentheses. -
func _load_item(item: String) -> void:Use the string from the chosen stock button to ask for one supply. -
if finished:Checks finished. The indented instructions below run only if this test passes. -
_report("Shift complete. The cabin is ready.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
if row != GALLEY:Refuse stock when Ari stands outside the galley. The location check runs before the capacity check. -
_report("Go back to the galley to load supplies.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
if cart.size() >= CAPACITY:Refuse this load when the cart already contains two or more entries. Comparison happens before the array changes. -
_report("Cart full. Two items fit.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
_remember()Calls _remember with the values in its parentheses. -
cart.append(item)Put one newly loaded supply at the end of the cart, after the location and capacity checks. -
turns += 1Spend exactly one turn for this accepted action, after all refusal branches have returned. -
_report(item + " loaded.")Calls _report with the values in its parentheses. -
func _select_seat(letter: String) -> void:Translate a tapped letter into a possible passenger in Ari’s current aisle row. -
var seat := str(row) + letterJoin the row’s text to the tapped letter. At row 2 with B this gives 2B. -
if not ORDERS.has(seat):Give clear feedback when the row-and-letter ID has no pending order record. This check prevents reading a missing key. -
selected = ""Clear the current choice so the game cannot reuse a passenger from another row or after a reset. -
_report(seat + " has no request.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
selected = seatHold the confirmed guest ID for outlining the correct tile and serving the correct request. -
if delivered.has(seat):Report that a known seat is already served. The same guest can be selected for inspection without receiving a second item. -
_report(seat + " has already been served.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
_report(seat + " requests " + str(ORDERS[seat]) + ".")Calls _report with the values in its parentheses. -
func _serve() -> void:Evaluate the current passenger and cart together before making a delivery. -
if finished:Checks finished. The indented instructions below run only if this test passes. -
_report("Shift complete. The cabin is ready.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
if selected.is_empty():Refuse service until the player chooses a requesting seat in Ari’s row. -
_report("Select a passenger in this row first.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
if delivered.has(selected):Protect the stock and score from duplicate service to the same guest. -
_report(selected + " has already been served.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var item: String = ORDERS[selected]Read the exact supply required by the confirmed seat ID. -
var slot := cart.find(item)Search from the front of the cart for the first matching supply index. A missing item returns -1. -
if slot == -1:Stop an incorrect delivery before any array entry or turn is spent. -
_report("Need " + item + " for " + selected + ".")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
_remember()Calls _remember with the values in its parentheses. -
cart.remove_at(slot)Consume exactly the matching supply. A different item stays in the cart. -
delivered.append(selected)Record the completed passenger ID exactly once so the HUD and finish check can use it. -
turns += 1Spend exactly one turn for this accepted action, after all refusal branches have returned. -
_report("Delivered " + item + " to " + selected + ".")Calls _report with the values in its parentheses. -
if delivered.size() == ORDERS.size():Recognise the last outstanding order and ask Ari to head back without ending the shift at the guest row. -
_report("All guests served. Walk back to the galley.")Calls _report with the values in its parentheses. -
func _remember() -> void:Take a snapshot of the state immediately before a legal change. -
history.append({Push one new snapshot onto the end of the history list. -
"row": row, "turns": turns, "selected": selected,Keep the numerical position, count and currently selected seat together as record fields. -
"cart": cart.duplicate(), "delivered": delivered.duplicate(), "finished": finishedCopy both arrays into the snapshot. The future live cart and list of served seats can change without mutating this earlier record. -
})Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
func _undo() -> void:Try to restore the state from just before the most recent accepted action. -
if history.is_empty():Stop with feedback rather than calling pop_back on an empty history. -
_report("Nothing to undo.")Calls _report with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var previous: Dictionary = history.pop_back()Remove and return the newest stored snapshot. This makes consecutive Undo presses step backwards one action at a time. -
row = previous["row"]Put Ari back at the saved position. -
turns = previous["turns"]Reinstate the earlier accepted action count. -
selected = previous["selected"]Reinstate the saved passenger selection so its outline and the service rules correspond. -
cart.assign(previous["cart"])Copy previous stock into the typed live cart. -
delivered.assign(previous["delivered"])Restore the former list of served guests, so an undone delivery becomes pending again. -
finished = previous["finished"]Restore whether the earlier state was a finished run. Undo can return a completed shift to an active scene. -
_report("Last action undone.")Calls _report with the values in its parentheses. -
func _restart() -> void:Reset all state belonging to the current training shift, then refresh the display. -
row = GALLEYPlace Ari back at row 0 as a new shift begins. -
turns = 0Return the elapsed action count to zero. -
selected = ""Clear the current choice so the game cannot reuse a passenger from another row or after a reset. -
cart.clear()Empty the current stock for the fresh attempt. -
delivered.clear()Make all order IDs pending again. -
finished = falseAllow movement, stock and serving again even if the earlier shift was complete. -
history.clear()Remove snapshots from the previous attempt so Undo cannot bring old activity back. -
_report("New shift. Load the cart at the galley.")Calls _report with the values in its parentheses. -
func _place_name() -> String:Translate the row number into the location words shown to the player. -
if row == 0:Use a place name for the galley rather than presenting it as passenger row zero. -
return "the galley"Return an understandable location label for row 0. -
return "row " + str(row)Turn a passenger row into a single piece of display text. -
func _report(words: String) -> void:Pass any updated action feedback through one place before refreshing. -
status = wordsSave the latest message before asking the screen to show it. -
_refresh()Calls _refresh with the values in its parentheses. -
func _refresh() -> void:Update the labels from the current saved game state whenever an action reports something. -
location_label.text = "Ari is at " + _place_name().capitalize()Render the current row or galley name in the location header. -
location_label.text += " · %d turns" % turnsAppend the accepted action count using whole-number formatting. -
note_label.text = statusPut the latest action report at the top of the feedback box. -
note_label.text += "\nCart: " + ("empty" if cart.is_empty() else ", ".join(cart))Add inventory on the next line. Show empty for an unstocked cart and join item names with commas otherwise. -
if finished:Checks finished. The indented instructions below run only if this test passes. -
location_label.text = "Shift complete · %d turns" % turnsUpdates location_label.text, which controls the words a player sees. The expression uses the text inside the quotes. -
queue_redraw()Ask Godot to repaint the cabin on the next frame using the updated row, selected seat and deliveries. -
func _draw() -> void:Godot calls this method to display the cabin layout and visible game state. -
var font := ThemeDB.fallback_fontUse Godot’s available fallback font for custom drawing on the cabin plan. -
draw_rect(Rect2(0, 0, 960, 540), INK)Paints a rectangle at the given position and size. -
draw_rect(Rect2(29, 92, 388, 414), PANEL)Paints a rectangle at the given position and size. -
draw_rect(Rect2(438, 92, 492, 414), PANEL)Paints a rectangle at the given position and size. -
draw_rect(Rect2(193, 126, 54, 256), Color("#132b3d"))Paints a rectangle at the given position and size. -
draw_string(font, Vector2(139, 137), "GALLEY", HORIZONTAL_ALIGNMENT_LEFT, -1, 13, GOLD)Paints a piece of text with a font at a position measured from the node's origin. -
for y in range(1, ROW_COUNT + 1):Draw passenger rows 1 through 6. The upper bound of range is excluded, so add 1 to include the last row. -
var seat_y := TOP_ROW_Y + (y - 1) * ROW_GAPConvert the logical row number to vertical screen pixels. Subtract one so the first passenger row starts at the configured origin. -
for index in range(SEAT_LETTERS.size()):Run the body once for each letter index. The current function uses that index to create or draw every seat in order. -
var x := SEAT_X[index]Use the stored pixel coordinate for the current seat letter to leave the central gap undisturbed. -
var letter := SEAT_LETTERS[index]Read the seat letter from its original position in the four-element list. -
var seat := str(y) + letterBuild the visual seat ID from the row being drawn rather than Ari’s current row. -
var seat_colour := Color("#315b70")Creates a variable named seat_colour. The expression builds a colour from these values. Godot infers the type from the first value. -
if ORDERS.has(seat):Use a request colour for the seats listed in the manifest. -
seat_colour = Color("#825b3a")Stores the new value in seat_colour. The expression builds a colour from these values. -
if delivered.has(seat):Report that a known seat is already served. The same guest can be selected for inspection without receiving a second item. -
seat_colour = Color("#366a59")Stores the new value in seat_colour. The expression builds a colour from these values. -
draw_rect(Rect2(x, seat_y, 49, 31), seat_colour)Paints a rectangle at the given position and size. -
draw_string(font, Vector2(x + 10, seat_y + 21), seat, HORIZONTAL_ALIGNMENT_LEFT, -1, 15, PAPER)Paints a piece of text with a font at a position measured from the node's origin. -
if seat == selected:Draw an outline around the current guest instead of changing the location marker. -
draw_rect(Rect2(x - 2, seat_y - 2, 53, 35), GOLD, false, 2.0)Paints a rectangle at the given position and size. -
var ari_y := 140 if row == 0 else TOP_ROW_Y + 15 + (row - 1) * ROW_GAPPlace Ari at the galley when row is zero. Otherwise convert the row to its passenger-seat centre. -
draw_circle(Vector2(220, ari_y), 11, MINT)Show a fixed x coordinate in the middle aisle and a y coordinate that follows Ari’s position. -
draw_string(font, Vector2(210, ari_y + 3), "ARI", HORIZONTAL_ALIGNMENT_LEFT, -1, 10, INK)Paints a piece of text with a font at a position measured from the node's origin. -
var order_line := "2B · Water 3C · Meal 6A · Blanket"Read the training manifest summary. It is written by hand in this exercise and needs editing if the manifest keys change. -
draw_string(font, Vector2(47, 401), order_line, HORIZONTAL_ALIGNMENT_LEFT, -1, 15, GOLD)Paints a piece of text with a font at a position measured from the node's origin. -
var progress := "%d / %d served" % [delivered.size(), ORDERS.size()]Calculate a string from the current number of served requests and the total on the manifest. -
draw_string(font, Vector2(47, 438), progress, HORIZONTAL_ALIGNMENT_LEFT, -1, 18, MINT)Paints a piece of text with a font at a position measured from the node's origin.
Find and fix a bug
If an old run comes back after restarting, make sure history.clear() runs inside _restart. If the screen keeps old text, verify _report runs last.
Try a change
Ages 10–12: exchange controls with a friend and complete a new shift after they press Restart. Ages 13–16: create a written test table with starting state, action and expected result for Restart, Undo and blocked input.