London Market 39 · Build the nine-shift noticeboard

Market Day London · Lesson 39 of 50 · Intermediate to advanced · About 35 min

Briar Lane gets busier as the day goes on. The noticeboard should show the first shift, later locked jobs and any award already earned.

Watercolour of a dry London market lane lined with bread, produce and flower stalls.
What you’ll make Create a shift menu from data and unlock the next shift on completion.

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/38 when the lesson builds on prior work, or copy the checkpoints/39 folder to try this lesson on its own. Read the file names in the steps before editing.

Build. Create buttons from titles. → Guard. Disable future shifts. → Record. Mark the completed entry. → Unlock. Open one more at most.
Build → Guard → Record → Unlock
Godot checkpoint window for Build the nine-shift noticeboard
From the running Godot checkpoint.

Build it step by step

Language and tools in this lesson Array[String], range, bind, disabled, mini.

  1. Import the editable checkpoint

    In the Godot 4.7.2 Project Manager, select Import and open the project.godot in this lesson folder. Open main.gd in the FileSystem dock. Press F5 to run the market and F8 to stop it before editing.

    Why it works This checkpoint already has a Control root with its script attached, so you can compare your edits to a working market scene.

  2. Lay out three groups

    Find the outer column loop in _ready. Point to the variables that choose a group's title and place it.

    for column in range(GROUPS.size()):

    Why it works Each column shows one stage of the day. The x offset moves equal distances across the noticeboard.

  3. Convert a row and column to one index

    In the inner loop calculate the index for column 1 and row 2. Check which button uses that title.

    var index := column * 3 + row

    Why it works Each group holds three jobs. Multiplying the group by three tells you where its sequence begins.

  4. Protect a future shift

    Click a locked shift, then find the guard in choose. Compare the guard with the disabled setting in refresh.

    if index > unlocked:

    Why it works The button shows that a choice is unavailable and the rule also refuses out-of-order requests.

  5. Unlock just one more job

    Complete shift 1. Read the update to unlocked and replay shift 1 twice before choosing shift 2.

    unlocked = mini(chosen + 1, TITLES.size() - 1)

    Why it works Only the highest unlocked shift can move the boundary forward. Earlier replays keep their check mark without opening extra jobs.

  6. Check the end of the list

    Complete all nine in order. Watch the badge and selected status after the ninth. Then test Reset noticeboard.

    unlocked = mini(chosen + 1, TITLES.size() - 1)

    Why it works mini stops the unlock boundary from going past the final title. Reset clears practice awards and starts at shift 1.

Watch the values change

  1. Open unlocked is zero.
    What you see. Only shift 1 is selectable.
  2. Complete shift 1 A record is stored, unlocked becomes 1.
    What you see. Shift 2 is now selectable.
  3. Complete shift 9 The boundary clamps to index 8.
    What you see. All nine stay visible with their completion marks.

Predict before you run Does replaying shift 1 after unlocking shift 4 unlock shift 5?

Reveal the answer

No. To unlock shift 5, complete shift 4.

Complete checkpoint

Nine labelled jobs are arranged in three groups with a check for completed ones and a text lock state.

main.gd

extends Control

const TITLES := ["First Crates", "A Loaf and a Posy", "Opening Queue", "Lunch Orders", "A Basket Each", "Busy Lunchtime", "Wet Cobbles", "Rain Detour", "Last Collection"]
const GROUPS := ["Morning Set-up", "Lunch Rush", "After the Rain"]
var chosen := 0
var unlocked := 0
var records: Dictionary = {}
var shifts: Array[Button] = []
var status: Label

func _ready() -> void:
	heading("Build the nine-shift noticeboard", "SHIFT MENU")
	status = label("", Vector2(44, 420), 19, MINT)
	for column in range(GROUPS.size()):
		label(GROUPS[column], Vector2(45 + column * 292, 143), 19, GOLD)
		for row in range(3):
			var index := column * 3 + row
			var entry := button(TITLES[index], Vector2(44 + column * 292, 180 + row * 61), choose.bind(index), 252)
			shifts.append(entry)
	button("Complete selected shift", Vector2(44, 463), complete, 247)
	button("Reset noticeboard", Vector2(304, 463), reset_lab, 220)
	refresh()

func choose(index: int) -> void:
	if index > unlocked:
		return
	chosen = index
	refresh()

func complete() -> void:
	records[chosen] = true
	if chosen == unlocked:
		unlocked = mini(chosen + 1, TITLES.size() - 1)
	refresh()

func reset_lab() -> void:
	chosen = 0
	unlocked = 0
	records.clear()
	refresh()

func refresh() -> void:
	for index in range(shifts.size()):
		shifts[index].disabled = index > unlocked
		var tag := "  ✓" if records.has(index) else ""
		shifts[index].text = "%02d  %s%s%s" % [index + 1, TITLES[index], tag, "  • Locked" if index > unlocked else ""]
	status.text = "Selected shift %02d • %s" % [chosen + 1, TITLES[chosen]]

func _draw() -> void:
	base()

const INK := Color("#173353")
const PAPER := Color("#fff4db")
const MINT := Color("#a8e0c1")
const GOLD := Color("#ffd291")

func heading(caption: String, topic: String) -> void:
	label("MARKET DAY LONDON     /     " + topic, Vector2(44, 36), 15, GOLD)
	label(caption, Vector2(44, 66), 31)

func label(words: String, at: Vector2, pixels: int = 20, ink: Color = PAPER) -> Label:
	var item := Label.new()
	item.text = words
	item.position = at
	item.add_theme_font_size_override("font_size", pixels)
	item.add_theme_color_override("font_color", ink)
	add_child(item)
	return item

func button(words: String, at: Vector2, action: Callable, width: float = 164.0) -> Button:
	var control := Button.new()
	control.text = words
	control.position = at
	control.custom_minimum_size = Vector2(width, 43)
	control.pressed.connect(action)
	add_child(control)
	return control

func base(colour: Color = Color("#193652")) -> void:
	draw_rect(Rect2(Vector2.ZERO, size), Color("#11263e"))
	draw_rect(Rect2(Vector2(22, 20), size - Vector2(44, 40)), colour)

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 ControlStarts with Godot's Control type. This script gets the abilities of that type and adds the game's own rules.
  2. const TITLES := ["First Crates", "A Loaf and a Posy", "Opening Queue", "Lunch Orders", "A Basket Each", "Busy Lunchtime", "Wet Cobbles", "Rain Detour", "Last Collection"]The order of the title array gives the sequence in which the nine shifts unlock.
  3. const GROUPS := ["Morning Set-up", "Lunch Rush", "After the Rain"]Creates a constant named GROUPS. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  4. var chosen := 0Creates a variable named chosen. The expression uses the whole number 0. Godot infers the type from the first value.
  5. var unlocked := 0unlocked stores the furthest allowed index. Zero means the first shift is available.
  6. var records: Dictionary = {}A shift index appears in records after the player completes it.
  7. var shifts: Array[Button] = []Creates a variable named shifts. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  8. var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here.
  9. func _ready() -> void:Godot calls this once after the scene and its children are ready. Use it to set up the room and connect controls.
  10. heading("Build the nine-shift noticeboard", "SHIFT MENU")Calls heading with the values in its parentheses.
  11. status = label("", Vector2(44, 420), 19, MINT)Stores the new value in status. The expression calls label with the values in its parentheses.
  12. for column in range(GROUPS.size()):The outer loop gives each of the three market periods a column.
  13. label(GROUPS[column], Vector2(45 + column * 292, 143), 19, GOLD)Calls label with the values in its parentheses.
  14. for row in range(3):The inner loop creates three numbered entries inside that period.
  15. var index := column * 3 + rowMultiply the column by three then add its row to map the grid into one list index.
  16. var entry := button(TITLES[index], Vector2(44 + column * 292, 180 + row * 61), choose.bind(index), 252)Creates a variable named entry. The expression calls button with the values in its parentheses. Godot infers the type from the first value.
  17. shifts.append(entry)Adds an item to the end of a list.
  18. button("Complete selected shift", Vector2(44, 463), complete, 247)Calls button with the values in its parentheses.
  19. button("Reset noticeboard", Vector2(304, 463), reset_lab, 220)Calls button with the values in its parentheses.
  20. refresh()Calls refresh with the values in its parentheses.
  21. func choose(index: int) -> void:Defines choose, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  22. if index > unlocked:The rule also runs inside the method. A call from a future input still cannot enter a locked stage.
  23. returnFinishes the function right here. Any later instructions in this function are skipped.
  24. chosen = indexStores the new value in chosen. The expression reads index.
  25. refresh()Calls refresh with the values in its parentheses.
  26. func complete() -> void:Defines complete, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  27. records[chosen] = trueRecord completion under the chosen shift index before applying its unlock rule.
  28. if chosen == unlocked:Unlock the next stage only when the chosen stage is the latest available one.
  29. unlocked = mini(chosen + 1, TITLES.size() - 1)mini() stops unlocked from passing the last shift. Array indexes start at zero, so subtract one from the count.
  30. refresh()Calls refresh with the values in its parentheses.
  31. func reset_lab() -> void:Defines reset lab, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  32. chosen = 0Stores the new value in chosen. The expression uses the whole number 0.
  33. unlocked = 0Stores the new value in unlocked. The expression uses the whole number 0.
  34. records.clear()Empties this collection.
  35. refresh()Calls refresh with the values in its parentheses.
  36. func refresh() -> void:Defines refresh, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  37. for index in range(shifts.size()):Repeats the indented instructions for each value in range(shifts.size()).
  38. shifts[index].disabled = index > unlockedThe Button’s disabled property blocks interaction with a choice that has not been unlocked.
  39. var tag := " ✓" if records.has(index) else ""The checkmark is built from the completion dictionary. A locked label is added separately by the next line.
  40. shifts[index].text = "%02d %s%s%s" % [index + 1, TITLES[index], tag, " • Locked" if index > unlocked else ""]The %02d formatting shows everyday one-based stage numbers like 01, with a leading zero.
  41. status.text = "Selected shift %02d • %s" % [chosen + 1, TITLES[chosen]]Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes.
  42. func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state.
  43. base()Calls base with the values in its parentheses.
  44. const INK := Color("#173353")Creates a constant named INK. The expression builds a colour from these values. Godot infers the type from the first value.
  45. const PAPER := Color("#fff4db")Creates a constant named PAPER. The expression builds a colour from these values. Godot infers the type from the first value.
  46. const MINT := Color("#a8e0c1")Creates a constant named MINT. The expression builds a colour from these values. Godot infers the type from the first value.
  47. const GOLD := Color("#ffd291")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value.
  48. func heading(caption: String, topic: String) -> void:Defines heading, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  49. label("MARKET DAY LONDON / " + topic, Vector2(44, 36), 15, GOLD)Calls label with the values in its parentheses.
  50. label(caption, Vector2(44, 66), 31)Calls label with the values in its parentheses.
  51. func label(words: String, at: Vector2, pixels: int = 20, ink: Color = PAPER) -> Label:Defines label, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  52. var item := Label.new()Creates a variable named item. The expression creates a new Label object. Godot infers the type from the first value.
  53. item.text = wordsUpdates item.text, which controls the words a player sees. The expression reads words.
  54. item.position = atUpdates item.position, which controls the node's local x and y location. The expression reads at.
  55. item.add_theme_font_size_override("font_size", pixels)Calls item.add_theme_font_size_override with the values in its parentheses.
  56. item.add_theme_color_override("font_color", ink)Calls item.add_theme_color_override with the values in its parentheses.
  57. add_child(item)Adds the new node to the scene tree so that Godot can run and draw it.
  58. return itemFinishes the function and hands its result back to the caller. The expression reads item.
  59. func button(words: String, at: Vector2, action: Callable, width: float = 164.0) -> Button:Defines button, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  60. var control := Button.new()Creates a variable named control. The expression creates a new Button object. Godot infers the type from the first value.
  61. control.text = wordsUpdates control.text, which controls the words a player sees. The expression reads words.
  62. control.position = atUpdates control.position, which controls the node's local x and y location. The expression reads at.
  63. control.custom_minimum_size = Vector2(width, 43)Updates control.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value.
  64. control.pressed.connect(action)Links a signal to the function that should run when the event happens.
  65. add_child(control)Adds the new node to the scene tree so that Godot can run and draw it.
  66. return controlFinishes the function and hands its result back to the caller. The expression reads control.
  67. func base(colour: Color = Color("#193652")) -> void:Defines base, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  68. draw_rect(Rect2(Vector2.ZERO, size), Color("#11263e"))Paints a rectangle at the given position and size.
  69. draw_rect(Rect2(Vector2(22, 20), size - Vector2(44, 40)), colour)Paints a rectangle at the given position and size.

Find and fix a bug

If the third column repeats the first, check that index includes column times three and row.

Try a change

Ages 10–12 can change the title of one shift. Ages 13–16 can connect a local progress record and verify the unlock boundary after a restart.