Cabin Crew Express · Lesson 10 of 50 · Beginner · About 36 min
Three passengers have already made a request. Ari can now walk up the aisle and inspect each request before learning how to carry items.

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/09 when the lesson builds on prior work, or copy the checkpoints/10 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 Dictionary, key, value, get default, is_empty, has, state.
-
Make an address-to-item manifest
Near SEAT_LETTERS, put REQUESTS. Keep the quotes around each address and its item value.
const REQUESTS: Dictionary = {"2B": "Water", "3C": "Meal", "6A": "Blanket"}Why it works A dictionary pairs keys with values. Here a seat address is the lookup key, while the value says which item the passenger wants.
-
Use the selected address as a key
In _ask_seat after seat_address, call get with the address and an empty string as the fallback.
var item := str(REQUESTS.get(seat, ""))Why it works get uses the exact address. str makes the result text so both the message and the emptiness test can read it.
-
Explain each lookup result
Add the if/else block. Keep the is_empty condition near the get line, then test a seat with and without a request.
var item := str(REQUESTS.get(seat, "")) if item.is_empty(): board.text = "%s | No request" % seat else: board.text = "%s | %s requested" % [seat, item]Why it works An empty string gets the No request message. The other branch fills one gap with the seat and the second with the requested item.
-
Mark the manifest seats
In the seat area of _draw, after drawing its label, check REQUESTS.has(seat) and add a mint dot for any mapped seat.
if REQUESTS.has(seat): draw_circle(point + Vector2(13, -14), 4.0, TEAL)Why it works has asks only whether the key exists. The dot can prompt you to ask, while the text on the sign tells you the item.
-
Run the practice route
Start at the galley. Tap Back twice and ask B. Walk back once and ask C. Continue to row 6 and ask A.
Why it works The three expected messages are Water, Meal and Blanket requested. Follow the route by rows and letters instead of by colour.
-
Prove that reading preserves the request
At row 2, ask A and then B twice. Explain why B still has a request on the second check.
Why it works This checkpoint reads the manifest without writing to it. Collecting and fulfilling an item will require new state in the next chapter.
Watch the values change
-
Ask seat 2B The dictionary has the key 2B with value Water.
What you see. The sign says 2B | Water requested. -
Ask seat 2A That key is absent, so get returns its empty fallback.
What you see. The sign says 2A | No request. -
Ask seat 6A The current row and column make 6A.
What you see. The sign says 6A | Blanket requested.
Predict before you run Would checking seat 3C twice mark the meal as delivered?
Reveal the answer
No. get reads its value. The script never removes, changes or serves the request when you ask.
Complete checkpoint
The board highlights 2B, 3C and 6A. Asking a marked seat reports Water, Meal or Blanket, and other seats report No request.
main.gd
extends Control
const GRID_ORIGIN := Vector2(64, 112)
const TILE := 54.0
const AISLE := 2
const LAST_ROW := 6
const NAVY := Color("#0a2138")
const AISLE_BLUE := Color("#4c8099")
const TEAL := Color("#8ce4ce")
var crew_row: int = 0
var board: Label
const SEAT_LETTERS: Array[String] = ["A", "B", "", "C", "D"]
const REQUESTS: Dictionary = {"2B": "Water", "3C": "Meal", "6A": "Blanket"}
func _ready() -> void:
board = Label.new()
board.position = Vector2(40, 48)
board.add_theme_font_size_override("font_size", 30)
add_child(board)
_refresh_board()
_add_button("Forward", Vector2(510, 164), _move.bind(-1))
_add_button("Back", Vector2(680, 164), _move.bind(1))
_add_button("Ask seat A", Vector2(510, 270), _ask_seat.bind(0))
_add_button("Ask seat B", Vector2(680, 270), _ask_seat.bind(1))
_add_button("Ask seat C", Vector2(510, 338), _ask_seat.bind(3))
_add_button("Ask seat D", Vector2(680, 338), _ask_seat.bind(4))
var hints := Label.new()
hints.text = "Move beside a passenger row to ask\nMint dot marks a request seat"
hints.position = Vector2(510, 430)
hints.modulate = Color("#a8d5e4")
add_child(hints)
func _refresh_board() -> void:
var place := "Galley" if crew_row == 0 else "Row %d" % crew_row
board.text = "Cabin Crew Express | Ari at %s" % place
func cell_centre(cell: Vector2i) -> Vector2:
return GRID_ORIGIN + Vector2(cell) * TILE + Vector2.ONE * (TILE / 2.0)
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NAVY)
for row in range(LAST_ROW + 1):
for column in range(5):
if row == 0 and column != AISLE:
continue
var point := cell_centre(Vector2i(column, row))
var tile := Rect2(point - Vector2.ONE * 25.0, Vector2.ONE * 50.0)
var paint := AISLE_BLUE if column == AISLE else Color("#193f58")
draw_rect(tile, paint)
if column != AISLE:
var seat := seat_address(row, column)
draw_string(ThemeDB.fallback_font, point + Vector2(-10, 5), seat, HORIZONTAL_ALIGNMENT_LEFT, -1, 15, Color.WHITE)
if REQUESTS.has(seat):
draw_circle(point + Vector2(13, -14), 4.0, TEAL)
var point := cell_centre(Vector2i(AISLE, crew_row))
draw_circle(point, 20.0, TEAL)
draw_string(ThemeDB.fallback_font, point + Vector2(-10, 5), "Ari", HORIZONTAL_ALIGNMENT_LEFT, -1, 15, NAVY)
func seat_address(row: int, column: int) -> String:
return "%d%s" % [row, SEAT_LETTERS[column]]
func _add_button(caption: String, point: Vector2, action: Callable) -> void:
var button := Button.new()
button.text = caption
button.position = point
button.custom_minimum_size = Vector2(152, 54)
button.pressed.connect(action)
add_child(button)
func _move(step: int) -> void:
var next_row := crew_row + step
if next_row < 0 or next_row > LAST_ROW:
board.text = "End of aisle | Ari stays at row %d" % crew_row
return
crew_row = next_row
_refresh_board()
queue_redraw()
func _input(event: InputEvent) -> void:
if not event is InputEventKey:
return
if not event.pressed or event.echo:
return
match event.keycode:
KEY_UP:
_move(-1)
KEY_DOWN:
_move(1)
_:
return
get_viewport().set_input_as_handled()
func _ask_seat(column: int) -> void:
if crew_row == 0:
board.text = "Galley | Walk to a passenger row first"
return
var seat := seat_address(crew_row, column)
var item := str(REQUESTS.get(seat, ""))
if item.is_empty():
board.text = "%s | No request" % seat
else:
board.text = "%s | %s requested" % [seat, item]
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 ControlAttach this script to a Control node so it can use labels and on-screen buttons. -
const GRID_ORIGIN := Vector2(64, 112)Use a fixed drawing origin so the aisle, seats and trainee share one coordinate system. -
const TILE := 54.0Centre neighbouring cells 54 pixels apart. The rectangles themselves are a little smaller. -
const AISLE := 2Column 2 is the third of the five visible columns. Ari stays within this centre aisle. -
const LAST_ROW := 6The last passenger row is 6. Row 0 is reserved for the galley. -
const NAVY := Color("#0a2138")Use this dark blue as the cabin background, and behind some text on the pale marker. -
const AISLE_BLUE := Color("#4c8099")Column 2 is the third of the five visible columns. Ari stays within this centre aisle. -
const TEAL := Color("#8ce4ce")Use the mint accent for Ari and for the small request indicators. -
var crew_row: int = 0This single integer identifies Ari’s position. The sign, marker and seat lookup all depend on it. -
var board: LabelKeep the same briefing Label available both to the setup and later callback functions. -
const SEAT_LETTERS: Array[String] = ["A", "B", "", "C", "D"]Keep one list entry per visual column. Its empty third entry lines up with the aisle. -
const REQUESTS: Dictionary = {"2B": "Water", "3C": "Meal", "6A": "Blanket"}Each key is one unique seat address. Its value is the item that Ari can read at that location. -
func _ready() -> void:Godot calls this once when the starting cabin Control is ready to create its children. -
board = Label.new()Create the actual Label and store its reference in the script-wide board variable. -
board.position = Vector2(40, 48)Give the sign a small upper-left margin on the 960 × 540 practice screen. -
board.add_theme_font_size_override("font_size", 30)Make the status easy to read without changing every Label in the project. -
add_child(board)Attach the briefing to this Control so Godot can draw it in the active scene. -
_refresh_board()Refresh what the player sees using the current cabin row. -
_add_button("Forward", Vector2(510, 164), _move.bind(-1))Create the forward button and remember a step of −1, because the front is row 0. -
_add_button("Back", Vector2(680, 164), _move.bind(1))Create the back button and remember a step of +1 towards the last cabin row. -
_add_button("Ask seat A", Vector2(510, 270), _ask_seat.bind(0))Use the bound column for this seat’s letter each time the button is pressed. The current row can change. -
_add_button("Ask seat B", Vector2(680, 270), _ask_seat.bind(1))Use the bound column for this seat’s letter each time the button is pressed. The current row can change. -
_add_button("Ask seat C", Vector2(510, 338), _ask_seat.bind(3))Use the bound column for this seat’s letter each time the button is pressed. The current row can change. -
_add_button("Ask seat D", Vector2(680, 338), _ask_seat.bind(4))Use the bound column for this seat’s letter each time the button is pressed. The current row can change. -
var hints := Label.new()Creates a variable named hints. The expression creates a new Label object. Godot infers the type from the first value. -
hints.text = "Move beside a passenger row to ask\nMint dot marks a request seat"Updates hints.text, which controls the words a player sees. The expression uses the text inside the quotes. -
hints.position = Vector2(510, 430)Updates hints.position, which controls the node's local x and y location. The expression packs x and y into one value. -
hints.modulate = Color("#a8d5e4")Updates hints.modulate, which controls the colour and transparency used to tint this node and its children. The expression builds a colour from these values. -
add_child(hints)Adds the new node to the scene tree so that Godot can run and draw it. -
func _refresh_board() -> void:Work out what to call the current row before preparing the latest sign. -
var place := "Galley" if crew_row == 0 else "Row %d" % crew_rowShow Galley for row zero. For a passenger row, insert its number after Row. -
board.text = "Cabin Crew Express | Ari at %s" % placeDisplay the named place using the same row value that controls the marker. -
func cell_centre(cell: Vector2i) -> Vector2:Convert a whole-number tile address into the pixel centre used to draw a tile or Ari’s marker. -
return GRID_ORIGIN + Vector2(cell) * TILE + Vector2.ONE * (TILE / 2.0)Add a scaled address and a half-tile shift to the grid origin. The returned Vector2 is measured in pixels. -
func _draw() -> void:Godot calls here when the screen needs repainting. Draw the background first, then the cells and marker. -
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NAVY)Paint over the whole viewport to provide the dark surface behind the cabin map. -
for row in range(LAST_ROW + 1):Visit row zero and the six passenger rows. range stops before LAST_ROW + 1. -
for column in range(5):For each row, inspect columns zero through four before advancing to the next row. -
if row == 0 and column != AISLE:At the galley, skip seats on both sides but keep the aisle square. -
continueSkip the rest of this inner-loop pass. Godot continues with the next column. -
var point := cell_centre(Vector2i(column, row))Calculate this one tile’s centre using the column as x and row as y. -
var tile := Rect2(point - Vector2.ONE * 25.0, Vector2.ONE * 50.0)Use a 50 × 50 rectangle centred on the point. Four pixels separate it from its neighbours. -
var paint := AISLE_BLUE if column == AISLE else Color("#193f58")Choose the lighter paint for column 2 and dark paint for any seat column. -
draw_rect(tile, paint)Paint the current tile. Its rectangle and colour were calculated on the two lines above. -
if column != AISLE:Only passenger seat tiles need an address label. -
var seat := seat_address(row, column)Ask the address helper to combine the current row number with this particular seat letter. -
draw_string(ThemeDB.fallback_font, point + Vector2(-10, 5), seat, HORIZONTAL_ALIGNMENT_LEFT, -1, 15, Color.WHITE)Draw the seat address just left of the tile centre. The default Godot font needs no extra files. -
if REQUESTS.has(seat):Test whether this particular address is present as a dictionary key. -
draw_circle(point + Vector2(13, -14), 4.0, TEAL)Place a mint dot toward the top-right corner of a seat tile that has a pending request. -
var point := cell_centre(Vector2i(AISLE, crew_row))The trainee stays in the aisle column. crew_row decides how far down the aisle to draw Ari. -
draw_circle(point, 20.0, TEAL)Place Ari’s teal circle over the tile rectangles. -
draw_string(ThemeDB.fallback_font, point + Vector2(-10, 5), "Ari", HORIZONTAL_ALIGNMENT_LEFT, -1, 15, NAVY)Identify the trainee on the teal circle, so the marker does not rely on colour alone. -
func seat_address(row: int, column: int) -> String:Receive the current human-facing row number and the column index of a seat. -
return "%d%s" % [row, SEAT_LETTERS[column]]Look up the letter by column and join it directly after the row number, producing labels such as 3C. -
func _add_button(caption: String, point: Vector2, action: Callable) -> void:Make the four seat buttons and movement buttons with one builder. Their captions, positions and press actions differ. -
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 = captionUpdates button.text, which controls the words a player sees. The expression reads caption. -
button.position = pointUpdates button.position, which controls the node's local x and y location. The expression reads point. -
button.custom_minimum_size = Vector2(152, 54)Give the clickable control room around its caption, for easier mouse or touch use in the prototype. -
button.pressed.connect(action)Tell Godot to call the given action only after that button emits its pressed signal. -
add_child(button)Adds the new node to the scene tree so that Godot can run and draw it. -
func _move(step: int) -> void:Apply a signed step to the aisle row. Both touchscreen buttons and keyboard arrows use this function. -
var next_row := crew_row + stepWork out the likely next row without changing the stored one yet. -
if next_row < 0 or next_row > LAST_ROW:Reject either a step past the galley or one past the last passenger row. -
board.text = "End of aisle | Ari stays at row %d" % crew_rowUpdates board.text, which controls the words a player sees. The expression uses the text inside the quotes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
crew_row = next_rowAn accepted step replaces Ari’s saved row. The following calls show the result. -
_refresh_board()Refresh what the player sees using the current cabin row. -
queue_redraw()Request a new drawing pass so Ari’s marker moves to the same row now shown in the sign. -
func _input(event: InputEvent) -> void:Listen for device input before controls consume the relevant arrow keys. Leave other keys to Godot. -
if not event is InputEventKey:Leave this handler immediately for any mouse, touch or other non-key event. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
if not event.pressed or event.echo:Ignore key releases and automatic repeats when a key is held down. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
match event.keycode:Use the pressed key’s code to choose which of the following movement branches runs. -
KEY_UP:The Up arrow heads toward the galley, which has a lower row number. -
_move(-1)Use the very same step as a tap on the Forward button. -
KEY_DOWN:The Down arrow heads toward the tail, which has a higher row number. -
_move(1)Use the very same step as a tap on the Back button. -
_:Handles every match value that the branches above did not handle. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
get_viewport().set_input_as_handled()Tell Godot this arrow has already been used for movement so a focused button cannot also consume it. -
func _ask_seat(column: int) -> void:Pair the button’s seat column with Ari’s current row to ask a nearby passenger. -
if crew_row == 0:Stop in the galley, where there are no passenger seats. -
board.text = "Galley | Walk to a passenger row first"Updates board.text, which controls the words a player sees. The expression uses the text inside the quotes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var seat := seat_address(crew_row, column)Creates a variable named seat. The expression calls seat_address with the values in its parentheses. Godot infers the type from the first value. -
var item := str(REQUESTS.get(seat, ""))Read the item for this specific address and ensure it is text. Use empty text for a seat without a request. -
if item.is_empty():A blank result means the seat has no requested service item in the practice manifest. -
board.text = "%s | No request" % seatUpdates board.text, which controls the words a player sees. The expression uses the text inside the quotes. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
board.text = "%s | %s requested" % [seat, item]Fill in Ari’s name, this particular update and the current whole request count in that order.
Find and fix a bug
If a mint dot shows but no request appears, compare the exact key you read with the generated address. 3C and C3 are different strings.
Try a change
Age 10–12: add a water request at 4D. Age 13–16: use one pass through REQUESTS.keys() to build and print a list of every requested seat.