Cruise Game 03 · Send dispatch updates with one function

Midnight Deck Dash · Lesson 03 of 50 · Beginner · About 25 min

Sol’s shipboard team needs a display that can update every time a bag is delivered.

A straight teak promenade with a cream cabin wall on one side and a ship railing above the moonlit ocean on the other.
What you’ll make Write a reusable function so the sign updates after each dispatch event.

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.

Keep one sign. Store its Label in a member variable. → Call by name. Pass different event words each time. → Read the current count. Use the latest number to update the sign.
Keep one sign → Call by name → Read the current count

Build it step by step

Language and tools in this lesson member variable, func, parameter, String, argument, void, scope.

  1. Give the sign a script-wide name

    Below the bag count, outside _ready, put var sign: Label. Inside _ready, replace var sign := Label.new() with sign = Label.new().

    var sign: Label

    Why it works A member variable is visible to several functions in the script. The assignment in _ready fills that name instead of making a second local variable.

  2. Define the update function

    Place post_status at the far left below _ready. Type event_name: String as its parameter and indent the two instructions inside.

    func post_status(event_name: String) -> void:
    	sign.text = "%s | %s: %d bags waiting" % [SHIP_NAME, event_name, orders_left]
    	print(sign.text)

    Why it works A parameter gives each call a way to pass in an event name. The void return type means the function hands no value back, though it still changes the sign.

  3. Send the opening event

    After add_child(sign), call post_status with the opening words. Keep the orders_left subtraction immediately below.

    	post_status("Night shift opens")
    	orders_left -= 1

    Why it works The text in quotes is an argument. It becomes event_name for this particular call.

  4. Send the delivery event

    Add the second call in _ready. Keep the spaces or tabs aligned with the first call. Save the file with Ctrl+S or Cmd+S.

    	post_status("One practice delivery")

    Why it works Both calls reuse the same text format. The second call sees orders_left after the subtraction, so it reports the latest number.

  5. Read the current display and history

    Run with F5. Match the first line of Output to the first call and the last line to the final call. Check which message remains on the game sign.

    Why it works The two calls run in sequence. The last assignment remains visible on the sign, while Output retains both messages.

Watch the values change

  1. Create and attach the sign The script-wide sign points to the Label.
    What you see. post_status can update it.
  2. Report the opening event_name holds the opening event and the count is 3.
    What you see. Output records the opening message.
  3. Subtract and report again The second argument is different and the count is 2.
    What you see. The current sign and final message show the practice delivery.

Predict before you run If you add another call saying Lift check and do not change orders_left, what stays the same?

Reveal the answer

The ship name and count of 2 stay the same. The event label changes, and Output gains a third message.

Complete checkpoint

The game sign ends on One practice delivery: 2 bags waiting and Output records both messages.

main.gd

extends Control

const SHIP_NAME := "Starlight Voyager"
var orders_left: int = 3
var sign: Label

func _ready() -> void:
	sign = Label.new()
	sign.position = Vector2(40, 50)
	sign.add_theme_font_size_override("font_size", 32)
	add_child(sign)
	post_status("Night shift opens")
	orders_left -= 1
	post_status("One practice delivery")

func post_status(event_name: String) -> void:
	sign.text = "%s | %s: %d bags waiting" % [SHIP_NAME, event_name, orders_left]
	print(sign.text)

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 ControlGives the root of this lesson the positioning and sizing features of a Godot Control, which is the type created by choosing User Interface in the scene editor.
  2. const SHIP_NAME := "Starlight Voyager"Stores the ship’s name as a constant. Every status message can read it from this one place.
  3. var orders_left: int = 3Starts the count at three luggage orders. The int type indicates this count uses whole numbers.
  4. var sign: LabelDeclares a script-wide reference with the Label type. _ready fills it, and other functions can then update the same on-screen label.
  5. func _ready() -> void:Godot calls this method after the scene is ready. Its indented steps make the dispatch label and any controls before the player can use them. It does not return a value.
  6. sign = Label.new()Makes the label and saves it to the script-wide sign variable. This line uses assignment without var so it does not create a second, local variable named sign.
  7. sign.position = Vector2(40, 50)Places the label 40 pixels from the left and 50 down from the top, relative to its parent.
  8. sign.add_theme_font_size_override("font_size", 32)Overrides just the label’s font_size theme setting for a large, readable dispatch sign.
  9. add_child(sign)Adds the Label to this node so it becomes part of the active scene and Godot can display its text.
  10. post_status("Night shift opens")Calls the reusable status function with the opening event name before the training delivery changes the count.
  11. orders_left -= 1Subtracts one from the previous count and saves the result back into orders_left. At the start of this lesson, three becomes two.
  12. post_status("One practice delivery")Calls the same status function after the subtraction, so the display now says that two bags remain.
  13. func post_status(event_name: String) -> void:Receives one event name as a String, then updates the on-screen sign and the editor log. The event_name value belongs to this call.
  14. sign.text = "%s | %s: %d bags waiting" % [SHIP_NAME, event_name, orders_left]Inserts ship name, event name and count into three gaps in order. Keeping the formatting here lets all status calls share it.
  15. print(sign.text)Shows the exact message assigned to the sign in the Output panel, which keeps early updates after a later message replaces them on screen.

Find and fix a bug

If sign is null in post_status, inspect the assignment in _ready. Writing var sign there creates another local variable and leaves the member sign empty.

Try a change

Add a third event after another small delivery. Predict whether Output will still show the opening status.