Cabin Crew Express · Lesson 03 of 50 · Beginner · About 26 min
Ari wants each crew update to follow the same format. Write it once and call it for different updates.

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/02 when the lesson builds on prior work, or copy the checkpoints/03 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 function, parameter, argument, member, scope, String, void.
-
Find the shared Label
Open main.gd and find var board: Label above _ready. Keep this declaration at the left margin.
var board: LabelWhy it works The member variable can be read by multiple functions. Godot stores a reference to the same Label in it.
-
Define a reporting function
Add post_briefing below _ready. Indent its two instruction lines one level.
func post_briefing(update: String) -> void: board.text = "%s | %s | Requests waiting: %d" % [CREW_NAME, update, requests_left] print(board.text)Why it works The update parameter receives different words each time the function is called. void means there is no return value.
-
Send the opening words
In _ready, call post_briefing after add_child. Use Service opens as the argument.
post_briefing("Service opens")Why it works The words in quotes are the value passed into update. The current request count is 3.
-
Send the new count
After the opening call, subtract one and call post_briefing again with Practice request completed.
requests_left -= 1 post_briefing("Practice request completed")Why it works Both calls use the same code. The second call reads the newer count after the subtraction.
-
Check both updates
Press F5. Match the two message lines in Godot Output to their order in the code.
Why it works The last mode of the scene has one Label assignment that stays visible. Output preserves both calls.
-
Make a third test call
Duplicate only the second post_briefing call and change its text. Keep the subtraction above it.
Why it works The last call provides new text. The request count keeps the value of 2 until another instruction changes it.
Watch the values change
-
Create and attach board board holds the Label shared by both functions.
What you see. post_briefing can now change its text. -
Call with Service opens update gets Service opens and the count is 3.
What you see. The sign changes. Output logs the update. -
Subtract and call again The second update reads 2.
What you see. The new sign stays visible and Output has both messages.
Predict before you run What happens if you remove the line that subtracts one?
Reveal the answer
Both messages still run, but both show three requests waiting.
Complete checkpoint
The final sign says Practice request completed and shows two requests waiting. Output also shows the earlier opening count.
main.gd
extends Control
const CREW_NAME := "Ari"
var requests_left: int = 3
var board: Label
func _ready() -> void:
board = Label.new()
board.position = Vector2(40, 48)
board.add_theme_font_size_override("font_size", 30)
add_child(board)
post_briefing("Service opens")
requests_left -= 1
post_briefing("Practice request completed")
func post_briefing(update: String) -> void:
board.text = "%s | %s | Requests waiting: %d" % [CREW_NAME, update, requests_left]
print(board.text)
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), Color("#0a2138"))
draw_rect(Rect2(Vector2(40, 106), Vector2(850, 2)), Color("#8ce4ce"))
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 CREW_NAME := "Ari"The trainee’s name appears in briefing messages and is fixed for this practice shift. -
var requests_left: int = 3Start the briefing with three whole requests. One practice update will reduce that number. -
var board: LabelKeep the same briefing Label available both to the setup and later callback functions. -
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. -
post_briefing("Service opens")Call the reusable update with different wording. It reads the request count as it is now. -
requests_left -= 1Read the old request count, subtract the one practice delivery, and store the new count. -
post_briefing("Practice request completed")Call the reusable update with different wording. It reads the request count as it is now. -
func post_briefing(update: String) -> void:Accept the new event’s words as update. The other values come from the script, so calls only need to provide this message. -
board.text = "%s | %s | Requests waiting: %d" % [CREW_NAME, update, requests_left]Fill in Ari’s name, this particular update and the current whole request count in that order. -
print(board.text)Copy the current sign to the Output log to keep a record after the sign changes. -
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), Color("#0a2138"))Paint over the whole viewport to provide the dark surface behind the cabin map. -
draw_rect(Rect2(Vector2(40, 106), Vector2(850, 2)), Color("#8ce4ce"))Paints a rectangle at the given position and size.
Find and fix a bug
If post_briefing cannot set board.text, confirm that _ready assigns board = Label.new(). Writing var board inside _ready creates a separate variable.
Try a change
Age 10–12: add a Galley is ready call. Age 13–16: test a call before add_child and explain why creating the Label is the important prerequisite for setting its text.