Learning Goals 3 min
By the end of this lesson you will be able to:
- Build a Checkpoint flag sprite that writes the player's current position into two variables — (checkpoint-x) and (checkpoint-y) — when the player touches it.
- Send the player to the checkpoint on death with go to x: (checkpoint-x) y: (checkpoint-y) instead of the level's start position.
- Reset the checkpoint variables to the level's start every time the player completes a level, so checkpoints are per-level, not permanent.
Warm-Up — death by a thousand restarts 7 min
After L04-20, level 3 has three chasers. Tough. When the cat dies, your current death script probably looks like this:
when I receive (player-died v)
go to x: (-200) y: (-100)
Predict — you've crossed three-quarters of level 3 and just touched a chaser. Where does the cat appear?
Reveal the answer
All the way back at x: −200, the level start. You have to fight past every chaser, every coin gap, every cloud platform again. That's not difficulty — that's punishment. Real games solve this with checkpoints: hit a flag halfway through, die later, respawn at the flag.
Today: a Checkpoint sprite, two new variables, and a tiny edit to the death script. Same death penalty (you still lose a life), but you only re-do half the level.
New Concept — saving a position into variables 15 min
A checkpoint is just two numbers in two variables — the x and y the player should respawn at. Whoever updates those numbers controls where you come back. The Checkpoint sprite writes the numbers when touched. The Player sprite reads them when dying.
The two variables
Make two new variables, For all sprites, so any sprite can read or write them:
- (checkpoint-x) — the x-coordinate to respawn at.
- (checkpoint-y) — the y-coordinate to respawn at.
Setting them at level start
When a level begins, the checkpoint is the level's start. The Stage (or the Player) initialises:
when I receive (level-up v)
set [checkpoint-x v] to (-200)
set [checkpoint-y v] to (-100)
The Checkpoint sprite overwrites them
Paint a small flag sprite. Place it halfway through level 1 (around x: 30, y: −100). The flag asks one question forever — am I being touched by the Player? — and the instant the answer is yes, it overwrites the two variables and changes colour as a visible confirmation:
when flag clicked
clear graphic effects
forever
if <touching (Player v) ?> then
set [checkpoint-x v] to (x position)
set [checkpoint-y v] to (y position)
change [color v] effect by (100)
end
end
The Player reads them on death
Tiny edit to the existing death script — replace the hard-coded coordinates with the variables:
when I receive (player-died v)
go to x: (checkpoint-x) y: (checkpoint-y)
Worked Example — one Checkpoint flag, one cat, three levels 12 min
We'll keep it focused — one Checkpoint sprite that you place by hand per level (a more advanced version would clone or auto-position, but that's L04-22+).
checkpoint-x and checkpoint-y. Next death: cat reappears at x:30, y:−100 instead of x:−200, y:−100.Step 1 — Make the two variables
Variables → Make a Variable → checkpoint-x, For all sprites. Same for checkpoint-y. Untick both watcher boxes (they're internal — players don't need to see them).
Step 2 — Paint the Checkpoint sprite
New sprite, paint a small white flag on a brown pole. Rename to Checkpoint. Drag it on the Stage to roughly x: 30, y: −100 for level 1's midpoint.
Step 3 — Checkpoint script (the saver)
when flag clicked
clear graphic effects
forever
if <touching (Player v) ?> then
set [checkpoint-x v] to (x position)
set [checkpoint-y v] to (y position)
change [color v] effect by (100)
end
end
Step 4 — Initialise checkpoint at level start (on the Player)
Three hats — one per level — so every level resets the checkpoint to its own start position. The cat from L04-19 already starts at different x/y per backdrop:
when backdrop switches to [level1 v]
set [checkpoint-x v] to (-200)
set [checkpoint-y v] to (-100)
when backdrop switches to [level2 v]
set [checkpoint-x v] to (-220)
set [checkpoint-y v] to (-80)
when backdrop switches to [level3 v]
set [checkpoint-x v] to (-210)
set [checkpoint-y v] to (-60)
Step 5 — Edit the death script
Find your existing when I receive (player-died v). Replace the hard-coded coordinates:
when I receive (player-died v)
change [lives v] by (-1)
go to x: (checkpoint-x) y: (checkpoint-y)
Step 6 — Reset the flag's colour on level-up
The flag turned pink when you touched it last level. For the next level it should look fresh again:
when I receive (level-up v)
clear graphic effects
Step 7 — Move the flag per level
For levels 2 and 3 the flag should sit at that level's midpoint. Add three position hats on the Checkpoint:
when backdrop switches to [level1 v]
go to x: (30) y: (-100)
show
when backdrop switches to [level2 v]
go to x: (0) y: (-80)
show
when backdrop switches to [level3 v]
go to x: (20) y: (-40)
show
Step 8 — Test the loop
Click the flag. Walk the cat to the midpoint flag — it should turn pink. Now deliberately walk into a Lipan. The cat should respawn at the flag, not at the level start. Beautiful — half the level skipped on death.
The Checkpoint sprite's full assembled stack
when flag clicked
clear graphic effects
forever
if <touching (Player v) ?> then
set [checkpoint-x v] to (x position)
set [checkpoint-y v] to (y position)
change [color v] effect by (100)
end
end
when I receive (level-up v)
clear graphic effects
What you just built: a save system. Tiny one — two numbers — but the exact same pattern as Super Mario's flag, Sonic's lamppost, every "respawn here" rock in every modern platformer.
Try It Yourself — three checkpoint drills 15 min
Goal: Add a play sound (Pop v) when the Checkpoint flag is touched, so the player hears that it saved. Place it inside the same if-then as the variable writes.
when flag clicked
forever
if <touching (Player v) ?> then
set [checkpoint-x v] to (x position)
set [checkpoint-y v] to (y position)
change [color v] effect by (100)
play sound (Pop v)
end
end
Think: The sound will replay every frame while the cat is touching. Either accept that (often fine — Pop is short) or add a small wait (0.3) seconds after the play.
Goal: Add a second Checkpoint sprite — three-quarters of the way through each level. Same script, different positions. Duplicate the Checkpoint sprite (right-click → duplicate), rename to Checkpoint2, edit its three position hats to be further right.
when backdrop switches to [level1 v]
go to x: (130) y: (-100)
show
Think: Both flags write into the same two variables. Whichever you touched last wins — that's correct behaviour. If you backtrack and touch the first flag again, your checkpoint moves backward, which might be weird. Add a check: if <(x position) > (checkpoint-x)> before saving.
Goal: Make the Checkpoint disappear after it's been used (so the player can't farm it). Add a (checkpoint-armed) variable, set to 1 at level start, set to 0 when touched, and only save while it's 1. After saving, the flag hides.
when flag clicked
forever
if <touching (Player v) ?> then
if <(checkpoint-armed) = (1)> then
set [checkpoint-x v] to (x position)
set [checkpoint-y v] to (y position)
set [checkpoint-armed v] to (0)
hide
end
end
end
Think: One-shot pickups (coins, power-ups, checkpoints that vanish) all share this armed flag + hide pattern. You'll re-use it constantly.
Mini-Challenge — the checkpoint that never moves 5 min
"Aishah's stuck flag"
Aishah's checkpoint works perfectly on level 1. She walks halfway, touches the flag, dies, respawns at the flag. Beautiful. But on level 2, dying sends the cat to level 1's midpoint — totally off the cave floor, sometimes off-screen. She wrote this on the Player:
when backdrop switches to [level1 v]
set [checkpoint-x v] to (-200)
set [checkpoint-y v] to (-100)
What did Aishah forget, and what's the smallest fix?
Reveal one valid solution
The checkpoint variables hold whatever they were last set to. When level 2 starts, nothing overwrites them, so they keep pointing at level 1's midpoint — wherever the flag was when she touched it. When she dies in the cave, the cat teleports to those (now wrong) coordinates.
Fix: add the missing two hats on the Player so every level kicks off by resetting the checkpoint to that level's start:
when backdrop switches to [level2 v]
set [checkpoint-x v] to (-220)
set [checkpoint-y v] to (-80)
when backdrop switches to [level3 v]
set [checkpoint-x v] to (-210)
set [checkpoint-y v] to (-60)
Lesson: variables are sticky. They keep their old value until something explicitly changes them. Any value that should be different per level needs a when backdrop switches to hat that resets it.
Recap 3 min
You built a save system. Two variables — (checkpoint-x) and (checkpoint-y) — hold the respawn position. A Checkpoint flag sprite writes them when the Player touches it, with a colour-change for visible confirmation. The death script reads them with go to x: (checkpoint-x) y: (checkpoint-y). Every level-up resets the checkpoint to that level's start so old midpoints don't carry over. Half-level resets instead of full-level. Same number of deaths, far less frustration.
- Checkpoint
- A position partway through a level where the player respawns on death, instead of going back to the level start. Stored as two variables: x and y.
- Respawn
- What happens after a death — the player sprite teleports back to a safe position. With checkpoints, that position is the latest checkpoint, not always the level start.
- Sticky variable
- A variable that keeps its old value across scenes (level changes, deaths, restarts) until something explicitly overwrites it. Helpful for saves; dangerous if you forget to reset.
- Per-level reset
- The pattern of overwriting state at the start of every level — (checkpoint-x) here, but the same idea applies to enemy positions, coin counts, timers, anything that shouldn't carry over.
- Visible confirmation
- A small visual change (colour, sound, animation) that tells the player something happened. Without it, the checkpoint feels broken even when it works.
Homework 2 min
The Checkpoint Pass. Continue your platformer project. Add a single Checkpoint flag and prove it works on all three levels.
- Two variables:
checkpoint-x,checkpoint-y, For all sprites, watchers off. - A new sprite called
Checkpoint— a small flag. Three when backdrop switches to hats positioning it at the midpoint of each level. - Checkpoint's main script: forever-if-touching-Player → write its x and y into the variables and change colour by 100.
- On the Player: three when backdrop switches to hats setting the checkpoint to the level's start position.
- Edit the existing when I receive (player-died v) to go to x: (checkpoint-x) y: (checkpoint-y).
- On the Checkpoint: when I receive (level-up v) → clear graphic effects, so each new level shows a fresh-looking flag.
Save as HW-L4-21-Checkpoint-Pass.sb3. Test by dying before reaching the flag (should respawn at level start) and dying after (should respawn at the flag).
Bring back next class:
- The
.sb3file. - Your answer to: "What if a level has TWO checkpoints? Does your current script handle that correctly? Test by adding a second Checkpoint sprite and walking past both — does respawn use the right one?"
Heads up for next class: SCR-L04-22 builds a Boss sprite for level 3 — a single big enemy with multiple phases (different behaviour as its health drops). It re-uses the level-gate pattern from L04-20 but gates on boss-health instead of level.