Cabin Crew 39 · Unlock flights on a mission board

Cabin Crew Express · Lesson 39 of 50 · Intermediate to advanced · About 38 min

Ari needs a way to practise a finished flight or select the next new challenge. Give each flight a clearly marked place.

Storage cupboards, water and folded supplies in the compact onboard galley.
What you’ll make Map nine flight names to labelled buttons and unlock one after a first completion.

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

List. Give each challenge an index and label. → Lay out. Calculate row and column. → Choose. Read the pressed button's index. → Unlock. Advance only on first completion.
List → Lay out → Choose → Unlock
Godot checkpoint window for Unlock flights on a mission board
From the running Godot checkpoint.

Build it step by step

Language and tools in this lesson Array, modulo, integer division, Callable.bind, disabled.

  1. Open the editable checkpoint

    Start Godot 4.7.2, choose Import in Project Manager and select the project.godot file for this lesson. Open main.gd in FileSystem, then press F5. Stop the game with F8 before editing.

    Why it works This folder is its own project with a Control scene and an attached script. You can run it without files from any other lesson.

  2. Store one list of flight names

    Open FLIGHTS and count the entries. Edit one flight name and run to see its card change.

    const FLIGHTS := [

    Why it works Each array position is a stable flight ID in this lab. The same list also supplies the board's length.

  3. Place flights in rows of three

    Read % 3 and / 3 inside the loop. Predict the position of the fourth flight, then check the board.

    var column := index % 3

    Why it works Remainder chooses a column. Integer division counts complete groups of three above it.

  4. Pass the right index

    Find choose_flight.bind(index). Unlock the second flight, then select it and check the status line.

    var card := button("", Vector2(48 + column * 291, 188 + row * 62), choose_flight.bind(index), 274)

    Why it works bind stores the correct number for each Button before anyone presses it. One handler can serve all cards.

  5. Unlock after a first completion

    Click Finish active flight twice without changing cards. Check why only one new card became ready.

    if active == completed:

    Why it works active must equal the first unfinished index. Replaying a completed flight does not advance progress.

  6. Prove the board stops at nine

    Finish flights in order to the final card. Click Finish again and inspect mini.

    completed = mini(completed + 1, FLIGHTS.size())

    Why it works The count cannot rise above the number of cards. The finished flights stay available to practise.

Watch the values change

  1. Open flight map completed is 0.
    What you see. Flight 1 is ready and flights 2–9 are locked.
  2. Finish Flight 1 completed increases to 1.
    What you see. Flight 1 gets a check and Flight 2 unlocks.
  3. Finish Flight 1 again active is below completed.
    What you see. The same two flights remain accessible.

Predict before you run Suppose you have completed three flights and replay Flight 1. Will Flight 5 become available?

Reveal the answer

No. Flight 4 is ready, and finishing an earlier flight again does not change completed.

Complete checkpoint

The board opens with one available flight. Completing a new flight activates the next, and replaying an old flight does not jump ahead.

main.gd

extends Control

const FLIGHTS := [
	"First Call", "Window Delivery", "Two Items",
	"Evening Meals", "Blanket Round", "Priority Cabin",
	"Cross-Cabin Plan", "Tight Turnaround", "Final Approach",
]
var completed := 0
var active := 0
var cards: Array[Button] = []
var status: Label

func _ready() -> void:
	heading("Choose a service flight on the mission board", "MAP")
	status = label("", Vector2(48, 126))
	for index in range(FLIGHTS.size()):
		var column := index % 3
		@warning_ignore("integer_division")
		var row := index / 3
		var card := button("", Vector2(48 + column * 291, 188 + row * 62), choose_flight.bind(index), 274)
		cards.append(card)
	button("Finish active flight", Vector2(48, 410), finish_active, 228)
	refresh()

func choose_flight(index: int) -> void:
	if index > completed:
		return
	active = index
	refresh()

func finish_active() -> void:
	if active == completed:
		completed = mini(completed + 1, FLIGHTS.size())
	refresh()

func refresh() -> void:
	status.text = "Active: %s     Progress: %d / %d" % [FLIGHTS[active], completed, FLIGHTS.size()]
	for index in range(cards.size()):
		var unlocked := index <= completed
		var marker := "✓" if index < completed else ("Ready" if unlocked else "Locked")
		var card: Button = cards[index]
		card.text = "%02d  %s / %s" % [index + 1, FLIGHTS[index], marker]
		card.disabled = not unlocked

func heading(caption: String, topic: String) -> void:
	label("CABIN CREW EXPRESS     /     " + topic, Vector2(48, 41), 15, Color("#ffca7b"))
	label(caption, Vector2(48, 73), 27)

func label(text: String, at: Vector2, pixels: int = 20, ink: Color = Color("#f7f4e9")) -> Label:
	var item := Label.new()
	item.text = text
	item.position = at
	item.add_theme_font_size_override("font_size", pixels)
	item.add_theme_color_override("font_color", ink)
	add_child(item)
	return item

func button(text: String, at: Vector2, action: Callable, width: float = 155.0) -> Button:
	var item := Button.new()
	item.text = text
	item.position = at
	item.custom_minimum_size = Vector2(width, 47)
	item.pressed.connect(action)
	add_child(item)
	return item

func _draw() -> void:
	draw_rect(Rect2(Vector2.ZERO, size), Color("#102336"))
	draw_rect(Rect2(Vector2(28, 25), Vector2(904, 483)), Color("#18364b"))

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 ControlStarts with Godot's Control type. This script gets the abilities of that type and adds the game's own rules.
  2. const FLIGHTS := [Give the mission board a fixed order of nine practice flights.
  3. "First Call", "Window Delivery", "Two Items",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  4. "Evening Meals", "Blanket Round", "Priority Cabin",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  5. "Cross-Cabin Plan", "Tight Turnaround", "Final Approach",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  6. ]Closes the parentheses, list or dictionary opened above. Any trailing comma separates this item from the next.
  7. var completed := 0Completed means how many successive flights are finished, starting before flight one.
  8. var active := 0Start by selecting the first card. Index zero displays as Flight 1.
  9. var cards: Array[Button] = []Creates a variable named cards. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  10. var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here.
  11. 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.
  12. heading("Choose a service flight on the mission board", "MAP")Calls heading with the values in its parentheses.
  13. status = label("", Vector2(48, 126))Stores the new value in status. The expression calls label with the values in its parentheses.
  14. for index in range(FLIGHTS.size()):Repeats the indented instructions for each value in range(FLIGHTS.size()).
  15. var column := index % 3Cycle through the three columns using the remainder.
  16. @warning_ignore("integer_division")This annotation gives Godot extra information about the declaration that follows.
  17. var row := index / 3Move down one display row for each group of three cards.
  18. var card := button("", Vector2(48 + column * 291, 188 + row * 62), choose_flight.bind(index), 274)Attach the indexed flight ID to that card’s callback before it can be played.
  19. cards.append(card)Keep the created Buttons so the scene can update labels and locking later.
  20. button("Finish active flight", Vector2(48, 410), finish_active, 228)Calls button with the values in its parentheses.
  21. refresh()Calls refresh with the values in its parentheses.
  22. func choose_flight(index: int) -> void:Defines choose flight, 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.
  23. if index > completed:Prevent selecting any flight beyond the next uncompleted mission.
  24. returnFinishes the function right here. Any later instructions in this function are skipped.
  25. active = indexStores the new value in active. The expression reads index.
  26. refresh()Calls refresh with the values in its parentheses.
  27. func finish_active() -> void:Defines finish active, 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.
  28. if active == completed:Only a first completion unlocks the next challenge.
  29. completed = mini(completed + 1, FLIGHTS.size())Stay inside the size of the flight list, even after another finish action.
  30. refresh()Calls refresh with the values in its parentheses.
  31. func refresh() -> 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.
  32. status.text = "Active: %s Progress: %d / %d" % [FLIGHTS[active], completed, FLIGHTS.size()]Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes.
  33. for index in range(cards.size()):Repeats the indented instructions for each value in range(cards.size()).
  34. var unlocked := index <= completedPermit earlier practice plus exactly one new challenge.
  35. var marker := "✓" if index < completed else ("Ready" if unlocked else "Locked")Explain the lock state with a written label or with the completed check.
  36. var card: Button = cards[index]Creates a variable named card. 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.
  37. card.text = "%02d %s / %s" % [index + 1, FLIGHTS[index], marker]Updates card.text, which controls the words a player sees. The expression uses the text inside the quotes.
  38. card.disabled = not unlockedEnforce the lock in the button as well as in the method that opens a flight.
  39. func heading(caption: String, topic: String) -> void:Defines heading, 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.
  40. label("CABIN CREW EXPRESS / " + topic, Vector2(48, 41), 15, Color("#ffca7b"))Calls label with the values in its parentheses.
  41. label(caption, Vector2(48, 73), 27)Calls label with the values in its parentheses.
  42. func label(text: String, at: Vector2, pixels: int = 20, ink: Color = Color("#f7f4e9")) -> Label:Defines 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.
  43. var item := Label.new()Creates a variable named item. The expression creates a new Label object. Godot infers the type from the first value.
  44. item.text = textUpdates item.text, which controls the words a player sees. The expression reads text.
  45. item.position = atUpdates item.position, which controls the node's local x and y location. The expression reads at.
  46. item.add_theme_font_size_override("font_size", pixels)Calls item.add_theme_font_size_override with the values in its parentheses.
  47. item.add_theme_color_override("font_color", ink)Calls item.add_theme_color_override with the values in its parentheses.
  48. add_child(item)Adds the new node to the scene tree so that Godot can run and draw it.
  49. return itemFinishes the function and hands its result back to the caller. The expression reads item.
  50. func button(text: String, at: Vector2, action: Callable, width: float = 155.0) -> Button:Defines 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.
  51. var item := Button.new()Creates a variable named item. The expression creates a new Button object. Godot infers the type from the first value.
  52. item.text = textUpdates item.text, which controls the words a player sees. The expression reads text.
  53. item.position = atUpdates item.position, which controls the node's local x and y location. The expression reads at.
  54. item.custom_minimum_size = Vector2(width, 47)Updates item.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value.
  55. item.pressed.connect(action)Links a signal to the function that should run when the event happens.
  56. add_child(item)Adds the new node to the scene tree so that Godot can run and draw it.
  57. return itemFinishes the function and hands its result back to the caller. The expression reads item.
  58. func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state.
  59. draw_rect(Rect2(Vector2.ZERO, size), Color("#102336"))Paints a rectangle at the given position and size.
  60. draw_rect(Rect2(Vector2(28, 25), Vector2(904, 483)), Color("#18364b"))Paints a rectangle at the given position and size.

Find and fix a bug

If two cards open the same flight, check bind(index). The target method must get the index of the card being created.

Try a change

Ages 10–12 can rename the nine practice flights. Ages 13–16 can change the arrangement to two columns and retest last-row navigation.