Cabin Crew Express · Lesson 02 of 50 · Beginner · About 25 min
Ari sees three practice requests waiting. Give that number a name so the game can read it later.

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/01 when the lesson builds on prior work, or copy the checkpoints/02 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 const, var, int, format string, assignment, -=, statement order.
-
Open the briefing scene
Open your working project and double-click main.gd in FileSystem. Save a copy if you want to return to Lesson 1.
Why it works You will reuse the briefing Label to show a count.
-
Name the trainee
Place CREW_NAME above _ready. Copy the quotes and colon-equals sign.
const CREW_NAME := "Ari"Why it works A const value stays the same in this script. Godot infers that the provided value is text.
-
Store a whole number
Put requests_left below the constant. Run once after setting it to 3.
var requests_left: int = 3Why it works The var value can change. The int hint identifies a whole number.
-
Write a formatted sign
Replace the sign assignment with a percent-format string. Find the two values in brackets and match them to the two gaps.
board.text = "%s | Requests waiting: %d" % [CREW_NAME, requests_left]Why it works %s inserts text and %d inserts a whole number. The percent expression fills the gaps from left to right.
-
Simulate a completed request
Below add_child(board), subtract one and print the current count. Press F5 and look at both the editor and game.
requests_left -= 1 print("After a practice delivery: ", requests_left)Why it works -= reads the old value, subtracts one and stores the answer. Here the sign was assigned before the subtraction.
-
Change which action happens first
In a working copy, move the subtraction above board.text and run it. Move the subtraction back when you are finished.
Why it works The new sign reads 2 because you built its text after the value changed.
Watch the values change
-
Enter _ready CREW_NAME is Ari and requests_left is 3.
What you see. The game has two named values. -
Set board.text The formatting expression reads 3.
What you see. The sign shows Requests waiting: 3. -
Subtract one requests_left changes to 2.
What you see. Output prints 2. The sign still shows 3.
Predict before you run Why does the sign keep showing 3 after requests_left changes to 2?
Reveal the answer
The sign already holds the string made with 3. Assign a new string to show the newer count.
Complete checkpoint
The sign reads Ari | Requests waiting: 3 and the editor prints After a practice delivery: 2.
main.gd
extends Control
const CREW_NAME := "Ari"
var requests_left: int = 3
var board: Label
func _ready() -> void:
board = Label.new()
board.text = "%s | Requests waiting: %d" % [CREW_NAME, requests_left]
board.position = Vector2(40, 48)
board.add_theme_font_size_override("font_size", 30)
add_child(board)
requests_left -= 1
print("After a practice delivery: ", requests_left)
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.text = "%s | Requests waiting: %d" % [CREW_NAME, requests_left]Updates board.text, which controls the words a player sees. The expression uses the text inside the quotes. -
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. -
requests_left -= 1Read the old request count, subtract the one practice delivery, and store the new count. -
print("After a practice delivery: ", requests_left)The output now displays the changed number. An earlier string already stored on the Label does not change itself. -
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 Godot flags the format expression, count its placeholders and bracketed values. The string expects two values in the same order.
Try a change
Age 10–12: start at five and predict both outputs. Age 13–16: subtract a second order and write a new formatted sign from the final count.