Midnight Deck Dash · Lesson 38 of 50 · Intermediate to advanced · About 36 min
Players need time to check their map. The luggage cart should wait with them, and the pause menu must still respond.

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/37 when the lesson builds on prior work, or copy the checkpoints/38 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 SceneTree.paused, Timer, timeout signal, process_mode, _exit_tree.
-
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.
-
Start a visible practice clock
Find clock.wait_time. Run and watch the patrol number increase every 0.8 seconds.
clock.timeout.connect(advance_cart)Why it works The Timer sends timeout each interval. advance_cart adds one to a counter you can see.
-
Pause the running scene
Press Pause game. Wait several seconds and compare the tick before and after.
get_tree().paused = trueWhy it works The SceneTree's paused flag disables processing for PAUSABLE nodes. The practice clock therefore cannot advance.
-
Make the escape route usable
Find pause_overlay.process_mode. Verify the Resume button still reacts even while the label is frozen.
pause_overlay.process_mode = Node.PROCESS_MODE_WHEN_PAUSEDWhy it works WHEN_PAUSED lets the overlay and inherited child buttons keep handling input inside the paused tree.
-
Resume without advancing twice
Press Resume, then pause again. Watch the counter pick up from its earlier value.
func resume_game() -> void:Why it works Clearing paused restarts ordinary processing. Hiding the panel afterwards returns the focus of the exercise to the deck.
-
Leave the practice scene safely
Restart from the editor and check that you see the live timer again. Review the teardown hook at the end of the script.
func _exit_tree() -> void:Why it works _exit_tree is called when the node leaves the tree. Clearing the flag prevents a paused state from carrying to another scene in this exercise.
Watch the values change
-
Run The normal timer emits timeout.
What you see. The patrol tick rises. -
Pause The tree stops PAUSABLE nodes while the overlay can accept input.
What you see. The tick freezes and Resume appears. -
Resume The pause flag clears and overlay hides.
What you see. The counter continues from its existing number.
Predict before you run If you give the entire overlay PAUSABLE instead of WHEN_PAUSED, what happens once you pause?
Reveal the answer
The Resume button inherits the pause mode, so it stops accepting input. Restore WHEN_PAUSED to keep the button working.
Complete checkpoint
The patrol counter stops during the pause, Resume works, and the counter continues afterwards.
main.gd
extends Control
var status: Label
var pause_overlay: Panel
var tick := 0
var clock: Timer
func _ready() -> void:
label("Midnight Deck Dash / Pause the deck", 30)
status = label("Cart patrol tick: 0", 90)
var freeze_button := button("Pause game", 52, 165, pause_game)
freeze_button.process_mode = Node.PROCESS_MODE_PAUSABLE
clock = Timer.new()
clock.wait_time = 0.8
clock.process_mode = Node.PROCESS_MODE_PAUSABLE
clock.timeout.connect(advance_cart)
add_child(clock)
clock.start()
build_pause_menu()
func build_pause_menu() -> void:
pause_overlay = Panel.new()
pause_overlay.position = Vector2(52, 238)
pause_overlay.size = Vector2(465, 146)
pause_overlay.process_mode = Node.PROCESS_MODE_WHEN_PAUSED
add_child(pause_overlay)
var hint := Label.new()
hint.text = "Game paused. The luggage cart waits."
hint.position = Vector2(16, 13)
pause_overlay.add_child(hint)
var resume := Button.new()
resume.text = "Resume game"
resume.position = Vector2(16, 63)
resume.custom_minimum_size = Vector2(200, 50)
resume.pressed.connect(resume_game)
pause_overlay.add_child(resume)
pause_overlay.hide()
func pause_game() -> void:
pause_overlay.show()
get_tree().paused = true
func resume_game() -> void:
get_tree().paused = false
pause_overlay.hide()
func advance_cart() -> void:
tick += 1
status.text = "Cart patrol tick: %d" % tick
func _exit_tree() -> void:
get_tree().paused = false
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. -
var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here. -
var pause_overlay: PanelDeclares pause_overlay for later use. A colon followed by a type says which kind of value belongs here. -
var tick := 0Creates a variable named tick. The expression uses the whole number 0. Godot infers the type from the first value. -
var clock: TimerDeclares clock for later use. A colon followed by a type says which kind of value belongs here. -
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 / Pause the deck", 30)Calls label with the values in its parentheses. -
status = label("Cart patrol tick: 0", 90)Stores the new value in status. The expression calls label with the values in its parentheses. -
var freeze_button := button("Pause game", 52, 165, pause_game)Creates a variable named freeze_button. The expression calls button with the values in its parentheses. Godot infers the type from the first value. -
freeze_button.process_mode = Node.PROCESS_MODE_PAUSABLEUpdates freeze_button.process_mode, which controls when the node is allowed to process, including while the game is paused. The expression reads Node.PROCESS_MODE_PAUSABLE. -
clock = Timer.new()Stores the new value in clock. The expression creates a new Timer object. -
clock.wait_time = 0.8Stores the new value in clock.wait_time. The expression reads 0.8. -
clock.process_mode = Node.PROCESS_MODE_PAUSABLELet the Timer run while the tree plays and stop updating when the SceneTree pauses. -
clock.timeout.connect(advance_cart)Ask Godot to call advance_cart every time the practice Timer reaches the end of its interval. -
add_child(clock)Adds the new node to the scene tree so that Godot can run and draw it. -
clock.start()Calls clock.start with the values in its parentheses. -
build_pause_menu()Calls build_pause_menu with the values in its parentheses. -
func build_pause_menu() -> void:Defines build pause menu, 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. -
pause_overlay = Panel.new()Stores the new value in pause_overlay. The expression creates a new Panel object. -
pause_overlay.position = Vector2(52, 238)Updates pause_overlay.position, which controls the node's local x and y location. The expression packs x and y into one value. -
pause_overlay.size = Vector2(465, 146)Updates pause_overlay.size, which controls the control's width and height. The expression packs x and y into one value. -
pause_overlay.process_mode = Node.PROCESS_MODE_WHEN_PAUSEDAllow the pause panel and controls that inherit its mode to receive updates while the rest of the game waits. -
add_child(pause_overlay)Adds the new node to the scene tree so that Godot can run and draw it. -
var hint := Label.new()Creates a variable named hint. The expression creates a new Label object. Godot infers the type from the first value. -
hint.text = "Game paused. The luggage cart waits."Updates hint.text, which controls the words a player sees. The expression uses the text inside the quotes. -
hint.position = Vector2(16, 13)Updates hint.position, which controls the node's local x and y location. The expression packs x and y into one value. -
pause_overlay.add_child(hint)Adds the new node to the scene tree so that Godot can run and draw it. -
var resume := Button.new()Creates a variable named resume. The expression creates a new Button object. Godot infers the type from the first value. -
resume.text = "Resume game"Updates resume.text, which controls the words a player sees. The expression uses the text inside the quotes. -
resume.position = Vector2(16, 63)Updates resume.position, which controls the node's local x and y location. The expression packs x and y into one value. -
resume.custom_minimum_size = Vector2(200, 50)Updates resume.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value. -
resume.pressed.connect(resume_game)Links a signal to the function that should run when the event happens. -
pause_overlay.add_child(resume)Adds the new node to the scene tree so that Godot can run and draw it. -
pause_overlay.hide()Makes this control invisible. -
func pause_game() -> void:Defines pause game, 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. -
pause_overlay.show()Makes this control visible. -
get_tree().paused = truePause the shared SceneTree so nodes assigned the pausable process mode stop running. -
func resume_game() -> void:Defines resume game, 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. -
get_tree().paused = falseClear the paused flag, returning the deck Timer and gameplay to their normal process mode. -
pause_overlay.hide()Makes this control invisible. -
func advance_cart() -> void:Defines advance cart, 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. -
tick += 1Increase the visible patrol counter by one when the Timer emits its signal. -
status.text = "Cart patrol tick: %d" % tickUpdates status.text, which controls the words a player sees. The expression uses the text inside the quotes. -
func _exit_tree() -> void:Defines exit tree, 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. -
get_tree().paused = falseClear the paused flag, returning the deck Timer and gameplay to their normal process mode. -
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 timer continues during the pause, check clock.process_mode and confirm the pause action changes get_tree().paused, rather than only showing a panel.
Try a change
Ages 10–12 can prove the pause holds for five seconds. Ages 13–16 can add a one-second grace message on resume, with the countdown deliberately assigned a different process mode.