Mobile Game 01 · Wake the museum with your first script

Museum of Lost Lights · Lesson 01 of 50 · Beginner · About 35 min

You’re inside the museum just after closing. The corridors are dark. Write an instruction that tells the museum to wake up for your first night shift.

A gouache painting of an Ocean Gallery with glass jellyfish exhibits, fossils and a deep teal floor.
What you’ll make Build and run a Godot project. Add a message to the game screen and read a second message in the editor’s Output panel.

Download the projects from the course page. In Godot’s Project Manager, choose Import, select project.godot, and use Run Project (F5). Start from the blank museum project in checkpoints/start. Keep the checkpoint ZIP intact and make edits in an extracted working copy.

Open the scene. The main Control has a script. → Run _ready. Godot starts the setup function. → Attach the new sign. The Label becomes a child. → Read two messages. The screen and Output show different messages.
Open the scene → Run _ready → Attach the new sign → Read two messages
Godot checkpoint window for Wake the museum with your first script
From the running Godot checkpoint.

Build it step by step

Language and tools in this lesson scene, node, extends, func, _ready, void, indentation, var, Label.new, add_child, print.

  1. Open the checkpoint or start fresh

    Extract the course download. In Godot’s Project Manager, choose Import, open the folder for Lesson 01 and select its project.godot file. To make the scene yourself instead, make a new project with the Compatibility renderer. In the empty Scene dock, choose User Interface. Save the resulting Control scene as main.tscn.

    Why it works A project holds the whole game. A scene is a saved piece of the game. A Control is the kind of node that is useful for menus, buttons and other parts of the interface.

  2. Find the script and match the root

    Select the root Control in the Scene dock. In the checkpoint, double-click main.gd in the FileSystem dock to read it. In your own project, click the Attach Script icon in the Scene dock, choose GDScript, set the path to res://main.gd, and choose Create. Replace the template with the checkpoint script.

    extends Control

    Why it works The script is a list of instructions attached to a node. The extends line says the script builds on everything a Control can already do.

  3. Give Godot a starting job

    Read the _ready line. Put the instructions below it one tab in from the left edge. Keep the final colon and use the same indentation for each instruction in the function.

    func _ready() -> void:

    Why it works A function groups instructions. Godot calls _ready automatically after this node and its children enter the scene tree. The arrow points to the type returned to the caller. void means this function sends no value back.

  4. Create the sign in two instructions

    Read the line with Label.new, then find where message.text is assigned. Say out loud what name you would use to change the sign later.

    var message := Label.new()
    	message.text = "Museum of Lost Lights"

    Why it works new() creates a Label. var makes a name, message, that refers to it. The := symbol lets Godot infer that message is a Label. The dot reaches the label’s text property. A pair of quotes marks the text value.

  5. Choose where the sign goes

    Read the Vector2 and add_child lines. Change the first number from 52 to 90. Then look for the font_size line to see why the title is easy to read.

    message.position = Vector2(52, 54)

    Why it works Vector2 stores two numbers for a position. On this screen x grows to the right and y grows down. Font size controls the size of the letters. add_child places the new Label under the current Control so it appears in the game.

  6. Check both places the game can speak

    Save with Ctrl+S or ⌘S. Press F6, or click Run Current Scene. Read the title in the game. Stop the game, then open the Output panel at the bottom of the Godot editor and read the print message.

    print("The Ocean Gallery is awake.")

    Why it works The player sees the Label. print sends a message to the developer’s Output panel so you can check what a script is doing.

Watch the values change

  1. Open main.tscn The Control root and script are loaded
    What you see. Godot knows what scene to run.
  2. Run the scene _ready creates and adds a Label
    What you see. The title appears at the position you set.
  3. Check the Output panel The print instruction has run
    What you see. You see the gallery’s private log message.

Predict before you run If you remove add_child(message) but leave the other instructions, which message will you still see?

Reveal the answer

The Output message will still appear. The Label exists in your code, but the scene cannot display it until you add it to the scene tree.

Complete checkpoint

The game displays Museum of Lost Lights near its top left. The Output panel displays The Ocean Gallery is awake. once for each run.

main.gd

extends Control

func _ready() -> void:
	var message := Label.new()
	message.text = "Museum of Lost Lights"
	message.position = Vector2(52, 54)
	message.add_theme_font_size_override("font_size", 38)
	add_child(message)
	print("The Ocean Gallery is awake.")

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 ControlThe scene root behaves like a Control, the kind of Godot node used for a game’s text, controls and other interface pieces.
  2. func _ready() -> void:Godot automatically calls this setup function after bringing this node and its children into the scene. The code below it prepares the first frame.
  3. var message := Label.new()Make a Label for the sign. The new node can hold words, and the rest of this function changes it through the name message.
  4. message.text = "Museum of Lost Lights"Set the exact words the player sees. The quotes mark the text and are left off the sign.
  5. message.position = Vector2(52, 54)Give the new sign x = 52 and y = 54. The first value moves it across the screen and the second moves it down.
  6. message.add_theme_font_size_override("font_size", 38)Give the sign a 38-pixel font. This style applies to this sign only.
  7. add_child(message)Add the created sign to the current Control. Once it joins the tree, Godot draws it.
  8. print("The Ocean Gallery is awake.")Write this message once to the developer’s Output panel. The Label continues to show its own separate words.

Find and fix a bug

If Godot highlights the first instruction after _ready, check that it is indented one tab and that the line above ends in a colon. If the game is blank without an error, check that the script is attached to the root and calls add_child(message).

Try a change

Ages 10–12: Write your own short sign. Keep both quotes. Ages 13–16: Create a second Label named subtitle at a different y position and add it to the scene. Leave a print instruction that helps you tell each Label apart.