- Learnt28 min · freezing one script, then all of them
- Basic24 min · press P, with a sign that says so
- Challenge 1–327 min · the runaway, the timer, and a pause that looks paused
- Extrabonus · slow motion
Review — last lesson 5 min
- Touching a bolt costs a life; the last one sets the state to over.
- A collision is tested every frame, so a
hurtflag is what stops one touch being sixty. - The cool-down lives in its own script, because a
waitin the main loop would freeze the game.
Quick-fire
Last lesson a wait in the wrong place froze the game by accident. Today you want to freeze it on purpose. Is the answer a wait?
Reveal the answer
Almost — it is wait until, which is different. A plain wait stops for a length of time you choose. wait until stops for as long as a condition says so, which is exactly what a pause is.
Today’s Topic 3 min
wait until <(state) = [play]>at the top of every loop- A key that toggles between two states
- Pausing clones, and pausing a clock
- Making a pause look paused
Learning outcome
By the end of this lesson you will be able to:
- Stop and restart a whole game with one key.
- Find the one script that ignored the pause, by measuring it.
- Say why Scratch’s timer is no use to a game that can be paused.
Learnt — stopping, and starting again 28 min
1 · A fourth state, and a key that toggles
Add paused to your states. The key that switches between it and play is a toggle — it asks where it is and goes the other way:
when [p v] key pressed
if <(state) = [play]> then
set [state v] to [paused]
else
set [state v] to [play]
end
2 · One block freezes a script
Put wait until <(state) = [play]> at the top of the loop body. While the game is paused the script sits there doing nothing at all; the moment the state goes back it carries on from exactly where it was.
repeat (40)
wait until <(state) = [play]>
next costume
change x by (8)
change [ticks v] by (1)
end
say [Forty ticks - however long you held P.] for (2.5) seconds
How to use this: Click the green flag, then press P a few times as the parrot crosses the Stage.
3 · Every loop, in every sprite
One sprite pausing is not a pause. Every loop that moves anything needs the same block — and that includes the loop inside a clone, because each clone is running its own copy:
when I start as a clone
show
repeat until <(x position) < (-230)>
wait until <(state) = [play]>
change x by (-6)
end
delete this clone
How to use this: Click the green flag, fly with the arrows, then press P. Look at the stars and the bolt, not the parrot.
Basic — press P 24 min
Open last lesson’s Storm Flight. Stars to collect, and a pause that works.
Step 1 — stars to fly through
- Add the
Starsprite. Under the flag it hides and becomes a spawner. - Its loop: wait until playing, go to the right-hand edge at a random height, clone itself, wait about half a second.
- The clone script: show, then drift left until off the edge, then delete.
- Inside the drift loop, test
touching (Parrot v)?— add a point and delete the clone.
Step 2 — the pause key
- Add the toggle script from above to the Parrot.
- Count
pauseswhile you are there, so you can prove it fired.
Step 3 — the wait, everywhere
- Put
wait until <(state) = [play]>at the top of the parrot’s flying loop. - The same at the top of the star spawner’s loop.
- The same inside the clone’s drift loop. This one gets forgotten.
Step 4 — the sign
- Add a sprite to be your sign — a plain button costume is fine — and put it near the top of the Stage.
- Its whole script is a forever loop: if the state is
paused, show and sayPAUSED - press P; otherwise hide.
when flag clicked
hide
go to x: (0) y: (120)
forever
if <(state) = [paused]> then
show
say [PAUSED - press P]
else
hide
say []
end
end
How to use this: Click the green flag, collect a few stars with the arrow keys, then press P. Press P again to carry on.
The parrot stops but the stars keep coming.
The star spawner’s loop has no wait, or it has one but the clone’s drift loop does not. Check both.
Pressing P does nothing.
The toggle is checking = against a word that does not match — Paused is not paused here because you typed it twice differently. Copy the word rather than retyping it.
P pauses but will not resume.
You used two if blocks rather than if / else. The first sets the state to paused, and the second immediately sees “paused” and sets it back — so it flickers, or never changes.
The sign appears but nothing else freezes.
The sign is the only script asking. That is Challenge 1 — every other loop needs the wait.
The parrot jumps forward when I resume.
The wait is below the movement rather than at the top of the loop body, so one more step was taken before the pause took hold.
The runaway
Find the script that ignored the pause by measuring it rather than squinting at the Stage.
- Give the parrot a tick counter and the bolt a tick counter.
- The parrot’s loop waits; the bolt’s does not.
- Pause for a few seconds and compare the two numbers.
How to use this: Click the green flag, let it run, press P, and wait. Watch the two counters separate.
Teacher note
Counting is the technique, not the answer. On a real project with twelve scripts, a temporary counter in each one finds the runaway in a minute, where watching the Stage can take twenty. Worth naming as a debugging habit — it is the same idea as Lesson 3-46’s say-tracing.
The clock that will not pause
Put Scratch’s own timer on the Stage next to a clock you keep yourself, and pause the game.
- Show the built-in
timerreadout. - Keep your own
my time, changed only while playing. - Pause for several seconds and compare.
How to use this: Click the green flag, watch both clocks, then hold the pause for a few seconds.
Teacher reveal — and a trap worth showing
forever
wait until <(state) = [play]>
wait (0.5) seconds
change [my time v] by (0.5)
end
Why halves and not tenths. Add 0.1 to a variable sixty times and Scratch shows 7.699999999999989. Computers store 0.1 as an almost-but-not-quite value and the error piles up. Halves and quarters are stored exactly, so they add up cleanly. Show them the broken version first — it is a thirty-second demonstration of something most adults never find out.
A pause that looks paused
Freezing is not enough — a player needs to see that it was deliberate.
- Every sprite dims while the game is paused.
- The sign appears over the top.
- Resuming undoes all of it, with nothing left dim.
How to use this: Click the green flag and press P. Everything on the Stage dims together, and brightens on resume.
Teacher note
The failure to watch for is a sprite that dims but never brightens, because its “clear” only runs in a branch that the resume does not reach. Ask them to pause and resume repeatedly — the dimming stacks up and the Stage goes black, which makes the bug obvious and memorable.
Slow motion
Prove your state machine is not just an on/off switch. Add a slow state: the same game, running at a quarter speed.
- The S key toggles between
playandslow. - The pause still works from either of them.
- The flying loop runs in both, with a wait added only in
slow.
How to use this: Click the green flag, press S for slow motion, P to pause, S again to speed up.
Teacher note
The “going further” answer: once states differ only by a number, they should be a number. play/slow/fast is three states doing one job; a speed variable does it better. States are for situations that behave differently, not for settings — and that distinction is what Lesson 3-24’s difficulty menu is built on.
Summary 5 min
wait until <(state) = [play]>at the top of a loop body is the whole of pause.- Every loop needs it — including the one inside a clone.
- A toggle key uses
if / else, not two ifs. - Scratch’s
timermeasures real time and cannot be paused. Keep your own. - Add 0.1 repeatedly and the number goes wrong. Halves and quarters are exact.
- A pause must look paused, and resuming must undo all of it.
- Pause
- A state in which everything waits, keeping its place.
- Toggle
- A control that switches between two things each time you use it.
- Game time
- Time that only passes while the game is being played.
- Runaway script
- A loop that never asks the state, and so never stops.
Hand in
Save your game. Next lesson finishes the arc: a score, a best that outlives the round, and a menu that adds one more state.