Midnight Deck Dash · Lesson 34 of 50 · Intermediate to advanced · About 36 min
A dim screen can make two colours hard to tell apart. Letters and names help every player read the night's delivery map.

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.


Build it step by step
Language and tools in this lesson Dictionary, Callable.bind, tooltip_text, StyleBoxFlat, theme override.
-
Open the editable checkpoint
In Godot Project Manager, choose Import, select this lesson's project.godot and click Import & Edit. Open main.gd from FileSystem and press F5 to see the finished checkpoint. Press F8 before trying a change.
Why it works The lesson scene already has a Control root with this script attached.
-
Name each deck symbol
Scan MARKS and say what the four marks mean. Press F5 and compare the visible symbols with the list.
{"mark": "L", "name": "Lift hatch"},Why it works Each Dictionary carries a short mark and a longer name. The loop uses that data to keep the label and button consistent.
-
Build one button per record
Follow index from the loop into describe.bind. Tap L, then A, and read the status in each case.
var icon := button(str(mark["mark"]), 52 + index * 145, 159, describe.bind(index), 124)Why it works bind remembers this button's index until it is pressed. Both buttons use the same function with different arguments.
-
Put the names on screen
Try using the board without hovering. Check that the guide still shows each plain-language name beside its mark.
var legend := label(str(mark["name"]), 223, 19)Why it works A tooltip is useful with a pointer. A visible legend helps players who tap or never hover.
-
Change the palette only
Press Switch contrast and compare the default and extra contrast backgrounds and borders.
tile.bg_color = Color.BLACK if extra_contrast else Color("#356276")Why it works The names and symbols come from MARKS and do not change. The style changes separately.
-
Test a keyboard user’s route
After resetting to standard contrast, press Tab and watch the focus outline. Activate an icon with Enter.
status.text = "Selected: %s (%s)" % [MARKS[index]["name"], MARKS[index]["mark"]]Why it works Button handles standard keyboard activation. Keeping focus feedback helps you predict which action will happen.
Watch the values change
-
Run The loop visits all four records.
What you see. Four distinct symbols and visible labels appear. -
Choose L Index 2 reaches describe.
What you see. The status names the lift hatch. -
Switch contrast Style changes but the list stays the same.
What you see. The four symbols keep their meanings.
Predict before you run Can someone tell a parcel from a lift hatch if both colours look alike?
Reveal the answer
Yes. The parcel has P and the name Parcel, while the hatch has L and the name Lift hatch.
Complete checkpoint
Names remain readable and each button reports its matching label in both palettes.
main.gd
extends Control
const MARKS := [
{"mark": "P", "name": "Parcel"},
{"mark": "A", "name": "Station A"},
{"mark": "L", "name": "Lift hatch"},
{"mark": "!", "name": "Luggage cart"},
]
var icons: Array[Button] = []
var status: Label
var extra_contrast := false
func _ready() -> void:
label("Midnight Deck Dash / Readable marks", 29)
status = label("Choose a deck symbol.", 79)
for index in range(MARKS.size()):
var mark: Dictionary = MARKS[index]
var icon := button(str(mark["mark"]), 52 + index * 145, 159, describe.bind(index), 124)
icon.tooltip_text = str(mark["name"])
icon.add_theme_font_size_override("font_size", 34)
icons.append(icon)
var legend := label(str(mark["name"]), 223, 19)
legend.position.x = icon.position.x
button("Switch contrast", 52, 318, toggle_contrast)
update_palette()
func describe(index: int) -> void:
status.text = "Selected: %s (%s)" % [MARKS[index]["name"], MARKS[index]["mark"]]
func toggle_contrast() -> void:
extra_contrast = not extra_contrast
update_palette()
status.text = "Extra contrast." if extra_contrast else "Standard contrast."
func update_palette() -> void:
for icon in icons:
var tile := StyleBoxFlat.new()
tile.set_corner_radius_all(9)
tile.bg_color = Color.BLACK if extra_contrast else Color("#356276")
tile.border_color = Color.WHITE if extra_contrast else Color("#95c1cd")
tile.set_border_width_all(3)
icon.add_theme_stylebox_override("normal", tile)
icon.add_theme_color_override("font_color", Color.WHITE)
func label(text: String, y: float, font_size: int = 25) -> Label:
var new_label := Label.new()
new_label.text = text
new_label.position = Vector2(52, y)
new_label.add_theme_font_size_override("font_size", font_size)
add_child(new_label)
return new_label
func button(text: String, x: float, y: float, action: Callable, width: float = 214.0) -> Button:
var control := Button.new()
control.text = text
control.position = Vector2(x, y)
control.custom_minimum_size = Vector2(width, 48)
add_child(control)
control.pressed.connect(action)
return control
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, size), Color("#112632"))
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 this script to a Control so the checkpoint can draw, size itself, place buttons and respond to input. -
const MARKS := [Creates a constant named MARKS. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
{"mark": "P", "name": "Parcel"},Starts a list or dictionary used as part of the instruction above. -
{"mark": "A", "name": "Station A"},Starts a list or dictionary used as part of the instruction above. -
{"mark": "L", "name": "Lift hatch"},Starts a list or dictionary used as part of the instruction above. -
{"mark": "!", "name": "Luggage cart"},Starts a list or dictionary used as part of the instruction above. -
]Closes the parentheses, list or dictionary opened above. Any trailing comma separates this item from the next. -
var icons: Array[Button] = []Creates a variable named icons. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here. -
var extra_contrast := falseCreates a variable named extra_contrast. The expression uses the yes-or-no value false. Godot infers the type from the first value. -
func _ready() -> void:Godot calls this setup function when the scene enters the running tree. void means the function gives the caller no value back. -
label("Midnight Deck Dash / Readable marks", 29)Calls label with the values in its parentheses. -
status = label("Choose a deck symbol.", 79)Stores the new value in status. The expression calls label with the values in its parentheses. -
for index in range(MARKS.size()):Repeats the indented instructions for each value in range(MARKS.size()). -
var mark: Dictionary = MARKS[index]Read the whole symbol-and-name record at the current index. -
var icon := button(str(mark["mark"]), 52 + index * 145, 159, describe.bind(index), 124)Creates a variable named icon. The expression calls button with the values in its parentheses. Godot infers the type from the first value. -
icon.tooltip_text = str(mark["name"])Give the player an extra text label on pointer hover, separate from the permanently visible legend. -
icon.add_theme_font_size_override("font_size", 34)Calls icon.add_theme_font_size_override with the values in its parentheses. -
icons.append(icon)Adds an item to the end of a list. -
var legend := label(str(mark["name"]), 223, 19)Creates a variable named legend. The expression calls label with the values in its parentheses. Godot infers the type from the first value. -
legend.position.x = icon.position.xAlign the word label beneath the corresponding button by copying its horizontal position. -
button("Switch contrast", 52, 318, toggle_contrast)Calls button with the values in its parentheses. -
update_palette()Calls update_palette with the values in its parentheses. -
func describe(index: int) -> void:Defines describe, 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. -
status.text = "Selected: %s (%s)" % [MARKS[index]["name"], MARKS[index]["mark"]]Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes. -
func toggle_contrast() -> void:Defines toggle contrast, 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. -
extra_contrast = not extra_contrastSwitch the presentation preference independently of what any symbol means. -
update_palette()Calls update_palette with the values in its parentheses. -
status.text = "Extra contrast." if extra_contrast else "Standard contrast."Updates status.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle. -
func update_palette() -> void:Defines update palette, 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. -
for icon in icons:Repeats the indented instructions for each value in icons. -
var tile := StyleBoxFlat.new()Creates a variable named tile. The expression creates a new StyleBoxFlat object. Godot infers the type from the first value. -
tile.set_corner_radius_all(9)Calls tile.set_corner_radius_all with the values in its parentheses. -
tile.bg_color = Color.BLACK if extra_contrast else Color("#356276")Use black in the extra contrast setting and standard ocean blue otherwise. -
tile.border_color = Color.WHITE if extra_contrast else Color("#95c1cd")Choose a crisp white border in extra contrast. The visible symbol and name stay the same. -
tile.set_border_width_all(3)Calls tile.set_border_width_all with the values in its parentheses. -
icon.add_theme_stylebox_override("normal", tile)Calls icon.add_theme_stylebox_override with the values in its parentheses. -
icon.add_theme_color_override("font_color", Color.WHITE)Calls icon.add_theme_color_override with the values in its parentheses. -
func label(text: String, y: float, font_size: int = 25) -> 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. -
var new_label := Label.new()Create a Godot node for visible text. The colon and equals together ask GDScript to infer the type from Label.new(). -
new_label.text = textCopy the supplied string into the actual label so the learner can read it. -
new_label.position = Vector2(52, y)Use a fixed 52-pixel left margin and the caller's chosen height in local design pixels. -
new_label.add_theme_font_size_override("font_size", font_size)Give this label the caller's text size. Other labels can keep their own sizes. -
add_child(new_label)Attach the Label to the scene root so Godot can draw and manage it. -
return new_labelGive the caller this particular label so a later delivery or move can change its words. -
func button(text: String, x: float, y: float, action: Callable, width: float = 214.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. -
var control := Button.new()Create a GUI button. It can respond to pointer taps and to the keyboard when focused. -
control.text = textShow the caller's chosen action name on the new button. -
control.position = Vector2(x, y)Place the action at the coordinates passed by the caller. -
control.custom_minimum_size = Vector2(width, 48)Ask the Control layout for at least the supplied width and 48 design pixels of height. -
add_child(control)Connect the new button to the visible scene root. -
control.pressed.connect(action)Connect the Godot pressed signal to the Callable received as action. The action runs on a press later. -
return controlReturn this button so the caller can customise it or keep its reference. -
func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state. -
draw_rect(Rect2(Vector2.ZERO, size), Color("#112632"))Draw the full dark blue practice backdrop from local (0, 0) to the current size. Shapes drawn later can appear above it.
Find and fix a bug
If the only explanation is a tooltip, check that every button creates a separate legend Label and sends its index to describe.
Try a change
Ages 10–12 can add an Exit symbol. Ages 13–16 can add custom hover and focus style overrides and compare all states with keyboard and mouse.