London Market 34 · Read orders without relying on colour

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

Rushing between striped awnings is easier when players can read the request in several ways.

Watercolour of a dry London market lane lined with bread, produce and flower stalls.
What you’ll make Give stall cards words, short marks, keyboard focus and a high-contrast palette.

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

Words. Name the request. → Marks. Give each item a quick label. → Focus. Support keyboard selection. → Contrast. Retain each meaning in both palettes.
Words → Marks → Focus → Contrast
Godot checkpoint window for Read orders without relying on colour
From the running Godot checkpoint.

Build it step by step

Language and tools in this lesson focus_mode, grab_focus, bind, toggle_mode, set_deferred.

  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. Use more than one sign

    Read STOCK and MARK, then change the display word Flower to Bouquet and run. Check that the F badge still matches the card.

    const MARK := ["A", "B", "F"]

    Why it works The name provides meaning and the letter helps a quick scan. Status can repeat the name as plain text.

  3. Create three controls from one loop

    Find the button call in the loop. Click the middle card and follow select_order, including the index it receives.

    var card := button("", Vector2(44 + index * 237, 207), select_order.bind(index), 216)

    Why it works bind carries a particular index with each button. The same function can select any market item.

  4. Offer keyboard focus

    Use Tab to move focus. Use Enter or Space to select a card. Find FOCUS_ALL and try FOCUS_NONE temporarily on a duplicate project.

    card.focus_mode = Control.FOCUS_ALL

    Why it works A regular Button supplies keyboard focus and a visible focus decoration. Removing focus makes that card harder to reach without touch.

  5. Mark the selection with text

    Read the formatting expression and choose Bread. Turn on High contrast and check the tick on the same card.

    cards[i].text = "[ %s ] %s%s" % [MARK[i], STOCK[i], "   ✓" if i == selection else ""]

    Why it works The tick comes from i equalling selection, not from a particular colour. The status names the same selected item.

  6. Test contrast and focus together

    Toggle High contrast while a card is selected, then move focus again. Inspect both font override lines.

    cards[i].add_theme_color_override("font_focus_color", Color.WHITE)

    Why it works Foreground text changes against a darker base, while independent words, marks and focus keep meaning available.

Watch the values change

  1. Start Selection is Apple and the first card has focus.
    What you see. Apple shows A and a tick.
  2. Tab and activate Bread selection changes to the bread index.
    What you see. The tick and status both say Bread.
  3. Toggle contrast Button palette changes.
    What you see. Selection survives and remains readable.

Predict before you run What distinguishes two cards if they both turn white in high contrast?

Reveal the answer

They still have their own words and marks, and only the selected card has a tick.

Complete checkpoint

Three named and marked buttons, a visible selection and an optional high-contrast palette.

main.gd

extends Control

const STOCK := ["Apple", "Bread", "Flower"]
const MARK := ["A", "B", "F"]
var cards: Array[Button] = []
var selection := 0
var contrast: Button
var status: Label

func _ready() -> void:
	heading("Read orders without relying on colour", "ACCESSIBILITY")
	label("Use Tab and Enter, or click a card.", Vector2(44, 128), 19, MINT)
	for index in range(STOCK.size()):
		var card := button("", Vector2(44 + index * 237, 207), select_order.bind(index), 216)
		card.focus_mode = Control.FOCUS_ALL
		card.custom_minimum_size.y = 58
		cards.append(card)
	contrast = button("High contrast", Vector2(44, 324), refresh, 204)
	contrast.toggle_mode = true
	status = label("", Vector2(44, 412), 23)
	refresh()
	cards[0].grab_focus()

func select_order(index: int) -> void:
	selection = index
	refresh()

func refresh() -> void:
	var high := contrast.button_pressed
	var colours := [Color("#ffb38d"), Color("#ffe291"), Color("#c8e3ff")]
	for i in range(cards.size()):
		cards[i].text = "[ %s ] %s%s" % [MARK[i], STOCK[i], "   ✓" if i == selection else ""]
		cards[i].add_theme_color_override("font_color", Color.WHITE if high else colours[i])
		cards[i].add_theme_color_override("font_focus_color", Color.WHITE)
	status.text = "Selected item: " + STOCK[selection]
	queue_redraw()

func _draw() -> void:
	base(Color("#14263c") if is_instance_valid(contrast) and contrast.button_pressed else Color("#26506b"))

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 STOCK := ["Apple", "Bread", "Flower"]Creates a constant named STOCK. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  3. const MARK := ["A", "B", "F"]Match the order of these short symbols to STOCK so one index selects both pieces of card text.
  4. var cards: Array[Button] = []Creates a variable named cards. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  5. var selection := 0Creates a variable named selection. The expression uses the whole number 0. Godot infers the type from the first value.
  6. var contrast: ButtonDeclares contrast for later use. A colon followed by a type says which kind of value belongs here.
  7. var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here.
  8. 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.
  9. heading("Read orders without relying on colour", "ACCESSIBILITY")Calls heading with the values in its parentheses.
  10. label("Use Tab and Enter, or click a card.", Vector2(44, 128), 19, MINT)Calls label with the values in its parentheses.
  11. for index in range(STOCK.size()):Repeats the indented instructions for each value in range(STOCK.size()).
  12. var card := button("", Vector2(44 + index * 237, 207), select_order.bind(index), 216)Each button passes its own inventory index to select_order(). The same loop lays the cards out side by side.
  13. card.focus_mode = Control.FOCUS_ALLFOCUS_ALL means keyboard Tab and pointer interactions can give this control focus.
  14. card.custom_minimum_size.y = 58Give each choice a taller clickable area for more comfortable selection.
  15. cards.append(card)Adds an item to the end of a list.
  16. contrast = button("High contrast", Vector2(44, 324), refresh, 204)Stores the new value in contrast. The expression calls button with the values in its parentheses.
  17. contrast.toggle_mode = trueStores the new value in contrast.toggle_mode. The expression uses the yes-or-no value true.
  18. status = label("", Vector2(44, 412), 23)Stores the new value in status. The expression calls label with the values in its parentheses.
  19. refresh()Calls refresh with the values in its parentheses.
  20. cards[0].grab_focus()Start with the first choice focused so a player can immediately navigate by keyboard.
  21. func select_order(index: int) -> void:Defines select order, 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. selection = indexStore the selected index first, then refresh the visible labels to match it.
  23. refresh()Calls refresh with the values in its parentheses.
  24. 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.
  25. var high := contrast.button_pressedRead the on/off state of the contrast Button. It stays pressed between updates until clicked again.
  26. var colours := [Color("#ffb38d"), Color("#ffe291"), Color("#c8e3ff")]Creates a variable named colours. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  27. for i in range(cards.size()):Repeats the indented instructions for each value in range(cards.size()).
  28. cards[i].text = "[ %s ] %s%s" % [MARK[i], STOCK[i], " ✓" if i == selection else ""]The formatting array supplies the symbol, name, and optional checkmark for the three %s placeholders from left to right.
  29. cards[i].add_theme_color_override("font_color", Color.WHITE if high else colours[i])In high contrast, make the regular card text white. At other times, pick the text colour listed for the card.
  30. cards[i].add_theme_color_override("font_focus_color", Color.WHITE)Keep the text white when that card has keyboard focus, whichever palette is selected.
  31. status.text = "Selected item: " + STOCK[selection]Repeat the selected item in words underneath the cards. The label can be read independent of the colouring.
  32. queue_redraw()Asks Godot to call _draw again on a later frame so the screen matches the new state.
  33. func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state.
  34. base(Color("#14263c") if is_instance_valid(contrast) and contrast.button_pressed else Color("#26506b"))is_instance_valid() lets the drawing code check the button safely if drawing begins before the control is ready.
  35. 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.
  36. 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.
  37. 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.
  38. 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.
  39. 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.
  40. label("MARKET DAY LONDON / " + topic, Vector2(44, 36), 15, GOLD)Calls label with the values in its parentheses.
  41. label(caption, Vector2(44, 66), 31)Calls label with the values in its parentheses.
  42. 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.
  43. var item := Label.new()Creates a variable named item. The expression creates a new Label object. Godot infers the type from the first value.
  44. item.text = wordsUpdates item.text, which controls the words a player sees. The expression reads words.
  45. item.position = atUpdates item.position, which controls the node's local x and y location. The expression reads at.
  46. item.add_theme_font_size_override("font_size", pixels)Calls item.add_theme_font_size_override with the values in its parentheses.
  47. item.add_theme_color_override("font_color", ink)Calls item.add_theme_color_override with the values in its parentheses.
  48. add_child(item)Adds the new node to the scene tree so that Godot can run and draw it.
  49. return itemFinishes the function and hands its result back to the caller. The expression reads item.
  50. 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.
  51. var control := Button.new()Creates a variable named control. The expression creates a new Button object. Godot infers the type from the first value.
  52. control.text = wordsUpdates control.text, which controls the words a player sees. The expression reads words.
  53. control.position = atUpdates control.position, which controls the node's local x and y location. The expression reads at.
  54. 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.
  55. control.pressed.connect(action)Links a signal to the function that should run when the event happens.
  56. add_child(control)Adds the new node to the scene tree so that Godot can run and draw it.
  57. return controlFinishes the function and hands its result back to the caller. The expression reads control.
  58. 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.
  59. draw_rect(Rect2(Vector2.ZERO, size), Color("#11263e"))Paints a rectangle at the given position and size.
  60. 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 Tab misses every item, check whether each card has FOCUS_ALL and whether grab_focus is called after cards are added.

Try a change

Ages 10–12 can replace letters with short, clear labels. Ages 13–16 can check a chosen foreground and background with a contrast calculator.