Market Day London · Lesson 02 of 50 · Beginner · About 22 min
Nia starts the day with three practice baskets. One free space at the counter tells her that a collection has already happened.

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 var, const, int, assignment, -=, %s and %d, order of execution.
-
Import the checkpoint
In Project Manager, import the Lesson 2 project.godot. Open main.gd on the Market Control and find the fields above _ready.
var orders_waiting: int = 3Why it works Values declared there can be shared by different functions on Market.
-
Read the fixed guide name
Find the constant GUIDE. Change it temporarily to another name and save if you want to try a new character.
const GUIDE := "Nia"Why it works const keeps one name for the whole run. The display reads that same name wherever it is used.
-
Fit words and numbers together
Find the board.text line. Match the first placeholder to GUIDE and the second to orders_waiting.
board.text = "%s • Baskets waiting: %d" % [GUIDE, orders_waiting]Why it works %s inserts text. %d inserts a whole number. GDScript reads the values from left to right in the array.
-
Subtract one basket
Follow the line just after the display instruction. Its short operation means read, subtract one and store.
orders_waiting -= 1Why it works Subtracting one changes the variable. The text already put into the label still holds the earlier number.
-
Compare two places
Play with F5 and read the sign. Stop with F8 and look for the changed number in Output.
print("After one practice collection, baskets waiting: ", orders_waiting)Why it works The board showed 3 before the change. The later print reads the new number 2.
-
Try a different start
Change the initial value to 5, save and play again. Compare the sign and Output.
var orders_waiting: int = 3Why it works A restart goes through _ready from the start. With 5 waiting before the deduction, the later output should read 4.
Watch the values change
-
Read the field values. GUIDE is Nia and orders_waiting is 3.
What you see. The sign reports 3 waiting. -
Run the subtraction. The number in memory becomes 2.
What you see. The sign still shows its earlier text. -
Read Output. The print instruction reads the current variable.
What you see. Output reports 2 waiting.
Predict before you run If you start with 6 waiting and keep one subtraction, what does Output show?
Reveal the answer
It shows 5. The sign shows 6 because it is written before the subtraction.
Complete checkpoint
The sign shows 3 baskets waiting. Output confirms that 2 remain after the practice collection.
main.gd
extends Control
const NIGHT := Color("#0d2335")
const PANEL := Color("#17374b")
const CREAM := Color("#fff4da")
const MINT := Color("#9ce4ce")
const GOLD := Color("#ffd789")
var board: Label
const GUIDE := "Nia"
var orders_waiting: int = 3
func _ready() -> void:
var title := Label.new()
title.text = "Market Day London"
title.position = Vector2(42, 34)
title.add_theme_font_size_override("font_size", 34)
title.modulate = CREAM
add_child(title)
board = Label.new()
board.position = Vector2(45, 88)
board.add_theme_font_size_override("font_size", 22)
board.modulate = MINT
add_child(board)
board.text = "%s • Baskets waiting: %d" % [GUIDE, orders_waiting]
orders_waiting -= 1
print("After one practice collection, baskets waiting: ", orders_waiting)
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NIGHT)
draw_rect(Rect2(32, 120, 431, 316), PANEL)
draw_rect(Rect2(487, 120, 437, 316), PANEL)
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 these screen-building instructions to a Godot Control. That gives the script positions, children and input events. -
const NIGHT := Color("#0d2335")Use this dark ink colour behind the market. The fixed colour is also used for lettering on the mint marker and brighter signs. -
const PANEL := Color("#17374b")Use one lighter shade to group the map and controls against the dark background. -
const CREAM := Color("#fff4da")Keep the title and labels light enough to read against dark panels. -
const MINT := Color("#9ce4ce")Use this accent to highlight the status label and Nia’s marker. -
const GOLD := Color("#ffd789")Mark utility labels and the collection point with a pale yellow that stands apart from the paving. -
var board: LabelSave the opening label so later methods can change it without needing to create a new one. -
const GUIDE := "Nia"Store the character name once, so announcements always identify Nia by the same name. -
var orders_waiting: int = 3Hold three practice collection baskets as a whole number. This number changes during the sample run. -
func _ready() -> void:Godot calls this once when the Market scene is ready to create the title, notice and controls. -
var title := Label.new()Create an unattached Label for the permanent title. It becomes visible when it is added to the scene. -
title.text = "Market Day London"Put the game name into the title label. The title stays fixed while smaller words underneath change. -
title.position = Vector2(42, 34)Leave a margin of 42 pixels from the left and 34 from the top. -
title.add_theme_font_size_override("font_size", 34)Set this title to a larger local font size. The rest of the labels can keep different sizes. -
title.modulate = CREAMSet the title’s drawing colour to the pale cream chosen above. -
add_child(title)Add the title to the running scene so Godot draws and maintains it. -
board = Label.new()Create the changing notice label and store it in the field used by other methods. -
board.position = Vector2(45, 88)Position the variable status words underneath the game name. -
board.add_theme_font_size_override("font_size", 22)Set a smaller font for status messages, which can be longer than the title. -
board.modulate = MINTTint the notice mint so it stands out as the changing information. -
add_child(board)Attach the notice beneath the title so the player sees the current message. -
board.text = "%s • Baskets waiting: %d" % [GUIDE, orders_waiting]Fill the first placeholder with Nia’s name and the second with the basket count as it exists at this moment. -
orders_waiting -= 1Read the number, deduct one practice collection and write the resulting value back. This does not change an older string already on screen. -
print("After one practice collection, baskets waiting: ", orders_waiting)Check the newly changed number in Output. It is one smaller than the number already printed on the notice. -
func _draw() -> void:Paint this section when Godot refreshes the Control. Draw the background first and the frontmost details last. -
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NIGHT)Fill the visible window so there is a consistent dark background behind the game panels. -
draw_rect(Rect2(32, 120, 431, 316), PANEL)Draw the dark rectangle under the tile map. -
draw_rect(Rect2(487, 120, 437, 316), PANEL)Draw an adjacent rectangle behind the controls and basket information.
Find and fix a bug
A message about format variables often means the format text and the list have different counts. Match every placeholder to one value.
Try a change
Ages 10–12 can try two starting counts. Ages 13–16 can calculate which displayed value changes if the subtraction moves before the board.text line.