Cabin Crew 06 · Give each seat an address

Cabin Crew Express · Lesson 06 of 50 · Beginner · About 29 min

An order saying 3C needs a seat address. A letter belongs to the cabin location, while the column index belongs to the grid.

A level view along the aisle of a regional aircraft, with two navy seats on each side.
What you’ll make Translate a column into a seat letter and draw addresses such as 2B and 3C.

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/05 when the lesson builds on prior work, or copy the checkpoints/06 folder to try this lesson on its own. Read the file names in the steps before editing.

Choose row and column. Try passenger row 2 and column 1. → Look up the letter. Index 1 gives B. → Format the address. Join 2 and B to get 2B.
Choose row and column → Look up the letter → Format the address
Godot checkpoint window for Give each seat an address
From the running Godot checkpoint.

Build it step by step

Language and tools in this lesson Array[String], index, ordered list, string format, return, filter, draw_string.

  1. Write the cabin’s column legend

    List A, B, a blank aisle, C, and D on paper from left to right. Number them from zero.

    Why it works A five-entry array can translate every physical column while keeping an empty entry for the aisle.

  2. Store the letters in order

    Place SEAT_LETTERS alongside the other constants. Keep the empty string between B and C.

    const SEAT_LETTERS: Array[String] = ["A", "B", "", "C", "D"]

    Why it works The type Array[String] tells Godot that the list contains text. Position 2 matches the aisle.

  3. Join a row number with its letter

    Add seat_address below cell_centre. Read row as a human-facing number and column as a zero-based index.

    func seat_address(row: int, column: int) -> String:
    	return "%d%s" % [row, SEAT_LETTERS[column]]

    Why it works The brackets look up the letter. %d receives the row, %s receives the letter, and return gives the joined address.

  4. Only build addresses for seats

    In the inner loop of _draw, put the conditional after draw_rect(tile, paint). Include the guard against using AISLE.

    			if column != AISLE:
    				var seat := seat_address(row, column)

    Why it works The centre is a walkway. Skipping its label prevents a misleading address with no seat letter.

  5. Put each address on the seat

    Read draw_string in the seat branch. Run and point to row 3, column 3.

    			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)

    Why it works The script uses the centre of the same tile. The small offset brings the label inside that rectangle.

  6. Check three addresses

    Read row 1 from left to right. Then find 2B and 6A in the game and say their column numbers.

    Why it works Reading the seat labels connects player vocabulary to the data your game will use for requests.

Watch the values change

  1. Read col 1 in row 2 Index 1 in the letter array is B.
    What you see. The script produces 2B.
  2. Read col 2 in row 2 The column matches AISLE.
    What you see. The board draws no seat address there.
  3. Read col 3 in row 3 Index 3 is C.
    What you see. The script produces 3C.

Predict before you run Which screen column holds seat 6D?

Reveal the answer

Column 4. The aisle counts as a column even though it has no letter.

Complete checkpoint

The seat addresses run A and B on the left and C and D on the right for every passenger row.

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 = 2
var board: Label
const SEAT_LETTERS: Array[String] = ["A", "B", "", "C", "D"]

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()

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)
	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]]

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
  1. extends ControlAttach this script to a Control node so it can use labels and on-screen buttons.
  2. const GRID_ORIGIN := Vector2(64, 112)Use a fixed drawing origin so the aisle, seats and trainee share one coordinate system.
  3. const TILE := 54.0Centre neighbouring cells 54 pixels apart. The rectangles themselves are a little smaller.
  4. const AISLE := 2Column 2 is the third of the five visible columns. Ari stays within this centre aisle.
  5. const LAST_ROW := 6The last passenger row is 6. Row 0 is reserved for the galley.
  6. const NAVY := Color("#0a2138")Use this dark blue as the cabin background, and behind some text on the pale marker.
  7. const AISLE_BLUE := Color("#4c8099")Column 2 is the third of the five visible columns. Ari stays within this centre aisle.
  8. const TEAL := Color("#8ce4ce")Use the mint accent for Ari and for the small request indicators.
  9. var crew_row: int = 2This single integer identifies Ari’s position. The sign, marker and seat lookup all depend on it.
  10. var board: LabelKeep the same briefing Label available both to the setup and later callback functions.
  11. 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.
  12. func _ready() -> void:Godot calls this once when the starting cabin Control is ready to create its children.
  13. board = Label.new()Create the actual Label and store its reference in the script-wide board variable.
  14. board.position = Vector2(40, 48)Give the sign a small upper-left margin on the 960 × 540 practice screen.
  15. board.add_theme_font_size_override("font_size", 30)Make the status easy to read without changing every Label in the project.
  16. add_child(board)Attach the briefing to this Control so Godot can draw it in the active scene.
  17. _refresh_board()Refresh what the player sees using the current cabin row.
  18. func _refresh_board() -> void:Work out what to call the current row before preparing the latest sign.
  19. 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.
  20. board.text = "Cabin Crew Express | Ari at %s" % placeDisplay the named place using the same row value that controls the marker.
  21. 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.
  22. 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.
  23. func _draw() -> void:Godot calls here when the screen needs repainting. Draw the background first, then the cells and marker.
  24. draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NAVY)Paint over the whole viewport to provide the dark surface behind the cabin map.
  25. for row in range(LAST_ROW + 1):Visit row zero and the six passenger rows. range stops before LAST_ROW + 1.
  26. for column in range(5):For each row, inspect columns zero through four before advancing to the next row.
  27. if row == 0 and column != AISLE:At the galley, skip seats on both sides but keep the aisle square.
  28. continueSkip the rest of this inner-loop pass. Godot continues with the next column.
  29. var point := cell_centre(Vector2i(column, row))Calculate this one tile’s centre using the column as x and row as y.
  30. 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.
  31. var paint := AISLE_BLUE if column == AISLE else Color("#193f58")Choose the lighter paint for column 2 and dark paint for any seat column.
  32. draw_rect(tile, paint)Paint the current tile. Its rectangle and colour were calculated on the two lines above.
  33. if column != AISLE:Only passenger seat tiles need an address label.
  34. var seat := seat_address(row, column)Ask the address helper to combine the current row number with this particular seat letter.
  35. 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.
  36. 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.
  37. draw_circle(point, 20.0, TEAL)Place Ari’s teal circle over the tile rectangles.
  38. 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.
  39. func seat_address(row: int, column: int) -> String:Receive the current human-facing row number and the column index of a seat.
  40. 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.

Find and fix a bug

If the C and D labels are shifted or Godot reports an invalid index, look for the missing empty string at index 2.

Try a change

Age 10–12: mark 4A and 5D on your sketch. Age 13–16: change the exterior letters in a copy and identify why addresses are display text and data keys at the same time.