Stage 9: The Stage
Keep your Scratch project tab open all week. Open in a new tab so you don’t leave the course.
an underwater backdrop, a timer, and looping music — all running on the Stage
how the Stage itself has code, separate from any sprite
a game world that feels like an actual ocean
Show the room — this is the first time we touch the Stage instead of a sprite:
- In the sprite pane, click the Stage button (far right, separate from the sprite list).
- Show the Backdrops tab — instead of Costumes for a sprite, the Stage has Backdrops.
- Click Choose a Backdrop → Underwater category → Underwater 1.
- Show the Sounds tab on the Stage. Add Dance Magic from the Loops category.
- Make a Time variable (For all sprites), check the box to show, then right-click on stage → large readout.
- Build two parallel scripts on the Stage: one for the timer count-up, one for music looping.
- Click the green flag. The underwater world appears, music plays, the timer ticks up.
Say "This code doesn't belong to a fish. It belongs to the world."
The big idea
For 8 stages we've been writing code on sprites — the Player Fish, the Enemy Fish. Today we discover that the Stage itself has code too.
The Stage is the world of the game. It has a backdrop (instead of a costume), it has sounds, and it has scripts. Anything that doesn't belong to any specific sprite — the background music, a game-wide timer, scene transitions — lives on the Stage.
Today we give the game its atmosphere:
- An underwater backdrop so the fish look like they're actually in the ocean.
- A timer that counts up while the player is alive — so the player (and the stats screen in Stage 10) knows how long the round lasted.
- Looping music so the game has a heartbeat that runs underneath the action.
The Stage
│
├── Backdrops tab → Underwater 1
│
├── Sounds tab → Dance Magic
│
└── Code tab → Script 1: timer (counts Time up)
Script 2: music (loops Dance Magic)
A new Control block makes its debut today: repeat until. It's like a forever loop, but it stops on its own when a condition becomes true. We use it to stop the timer when playerAlive = 0 (when the game ends).
- Stage
- the world of the game — the area where everything happens
- backdrop
- the Stage's background image (like a costume, but for the Stage)
- repeat until
- a Control block that loops over and over until a condition becomes true
- play sound until done
- a Sound block that plays a clip and waits for it to finish before moving on
- Time
- our timer variable — the number of seconds since the game started
Stage 8 should be done — your game has a full eat-or-be-eaten loop. The Player can win, lose, and watch the score climb.
Build it
Step 1 — Select the Stage
In the sprite pane (bottom-right), look to the right of the sprite list. You should see a Stage button with a small thumbnail of the white default backdrop.
Click it. The sprite pane now shows the Stage selected (its outline highlights). The Code, Backdrops, and Sounds tabs at the top of the editor now refer to the Stage, not any sprite.
Step 2 — Add the Underwater 1 backdrop
Click the Backdrops tab. The Stage starts with one blank backdrop.
At the bottom-left of the panel, click Choose a Backdrop (the icon at the bottom). The library opens.
Click the Underwater category. Find Underwater 1 — a colorful underwater scene with coral and rocks. Click it.
The new backdrop is added. The Stage immediately shows the underwater scene. The game has a world now.
Step 3 — Add the Dance Magic sound
Click the Sounds tab. Click Choose a Sound.
Click the Loops category. Find Dance Magic (a short loopable music track). Click it.
You now have a music track ready to play.
Step 4 — Make the Time variable
Click the Code tab on the Stage.
In the block palette, click Variables. Click Make a Variable.
- Name:
Time(capital T — matches what we'll use in Stage 10's stats screen) - Select For all sprites.
- Click OK.
A Time variable now exists. By default it's shown on the stage. Drag the readout to where you want it — bottom-left works well.
Right-click the readout on the stage → large readout. The number becomes big and easy to read.
Step 5 — Build the timer script
This script counts the Time variable up by 1 every second, until the player dies.
In the Stage's code area, drag in:
Stage timer script
when green flag clicked switch backdrop to [Underwater 1 v] set [Time v] to (0) wait (1) seconds repeat until <(playerAlive) = (0)> change [Time v] by (1) wait (1) seconds end
How to build it:
- when green flag clicked — Events.
- switch backdrop to (Underwater 1) — Looks. Pick from the dropdown.
- set Time to 0 — Variables. Make sure Time is selected in the dropdown.
- wait 1 seconds — Control.
- repeat until (<empty>) — Control. In the diamond slot, build
playerAlive = 0using Operators and Variables. - Inside the repeat-until: change Time by 1 and wait 1 seconds.
The pattern is: "every second, bump Time up by 1, until the player is no longer alive."
Step 6 — Build the music script
The music script is a SEPARATE script, also triggered by the green flag.
In the Stage's code area, drag in:
Stage music script
when green flag clicked set volume to (50) % wait (1) seconds repeat until <(playerAlive) = (0)> play sound [Dance Magic v] until done end
How to build it:
- when green flag clicked — another Events block, separate from the first script.
- set volume to 50% — Sound block. Half volume so the chomp sound is still audible.
- wait 1 seconds — gives the game a moment to set up.
- repeat until (playerAlive = 0) — same condition as the timer.
- play sound (Dance Magic) until done — Sound block. Until done means "play the whole track before moving to the next loop iteration."
The pattern: "play the track all the way through, then check if the game is still on, then play it again, until the game ends."
Step 7 — Test the world
Click the green flag.
- The underwater backdrop appears.
- Music starts after a 1-second pause.
- The Time variable starts counting up: 1, 2, 3...
- When the player dies (touch a bigger fish), the music stops and the timer freezes.
Save your project.
Understand it
The most important idea today is that the Stage has its own code, separate from any sprite. The Stage is where world-level things belong: the backdrop, the music, the global timer. Things that don't belong to the Player Fish or the Enemy Fish.
Putting the timer on the Stage is a deliberate design choice. We could have put it on the Player sprite — but then if the Player hides at the end of the game, the timer would stop counting before the death animation finishes. The Stage never hides, so its scripts can keep running for the brief moments after the player dies, ensuring the stats screen (Stage 10) gets a complete Time value.
The repeat until (playerAlive = 0) block is the cleaner cousin of forever. forever runs without stopping; repeat until runs until something happens. We use it because we know the loop should stop — at game end. Cleaner than forever plus a manual "stop" call.
The wait 1 seconds at the start of both scripts is a small but important detail. When the green flag is clicked, all of Scratch's scripts start at once — sprite initializations, variable resets, the cloning loop, the music. Without that 1-second pause, the music would try to start before everything else is ready, which sometimes causes a missed first beat. The wait gives the game room to settle.
The play sound until done vs the simpler start sound matters here. start sound plays immediately and returns; the next iteration of the loop would fire instantly, playing the music a thousand times per second (mostly inaudible). play sound until done waits for the whole track to finish, then moves on. So the music plays as a clean loop — one full play of Dance Magic, then another, then another.
The set volume to 50% is a real game-design move. Game music is usually mixed quieter than sound effects so the sound effects (chomp, bubbles, eggs) can punch through. 50% gives the player music and clear feedback for actions.
Try this
Try this
Three short experiments. Predict before you run, then test your guess.
Replace repeat until (playerAlive = 0) with forever in the timer script. Predict what happens when the player dies. Try it. What changed about the timer? Put repeat until back.
Try a different backdrop — switch to Underwater 2 or Underwater 3 in the Backdrops tab dropdown. Does the game feel different? Which backdrop fits the feel of your fish swarm best?
Stage 10 builds the final score screen. Look at the variables your game now tracks: playerSize, playerAlive, enemySize, fishEaten, score, Time. Which three or four are most useful to display on a final score screen for parents?
Test your stage
- The Stage has the Underwater 1 backdrop.
- The Stage has Dance Magic in its Sounds tab.
- You have a Time variable shown on the stage as a large readout.
- Clicking the green flag starts the timer counting up: 1, 2, 3...
- Music starts after a brief delay and keeps looping.
- When the player dies (touch a bigger enemy), the timer stops and the music stops.
- Your project is saved.
- Design check. Play a full round. Does the music make the game feel more alive or distracting? Music is part of the experience — tune the volume to taste.
If it breaks
- The timer doesn't count. Three suspects. First, is the script on the Stage (not on a sprite)? Second, is
change Time by 1inside therepeat untilloop? Third, is the Time variable set to For all sprites? - The timer keeps counting after I lose. The
repeat until (playerAlive = 0)condition is missing or broken. Make sureplayerAliveis the variable name on the left and0is on the right. - The music never starts. Two suspects. First, did you click
play sound (Dance Magic)— and is Dance Magic in the dropdown? Second, is the script on the Stage (the sound has to live on whichever object plays it)? - The music plays once and stops. The
repeat untilis missing orplay sound until doneis outside the loop. Inside, the play-sound-until-done block runs once, finishes, then the loop comes back to play it again. - The music is too loud / too quiet. Tune the
set volume to 50value. Try30or70. The right level is whatever lets the player hear the chomp sound clearly. - Pressing the green flag plays multiple music tracks at once. You clicked the flag before the previous round finished. Click the red stop sign first to clear all running sounds, then click the green flag fresh.
This stage is structurally lighter than Stages 7 and 8 — give kids breathing room. The new conceptual move is the Stage has code, which is small but important.
The single most common mistake: putting the timer or music script on the Player sprite instead of the Stage. Walk the room after Step 4 and confirm everyone clicked the Stage button before they started coding.
The second most common: the Time variable made as For this sprite only. Since the Stage isn't really "a sprite" in the same way, scoping it correctly matters — For all sprites is the right choice. Stage 10's score screen will need to read this variable.
The repeat until block is a slight pace change from forever — most kids have only used forever so far. Specifically demo the difference: forever runs until you press stop; repeat until runs until a condition. The clean exit on playerAlive = 0 is the lesson.
For pacing: Step 1–4 (selecting Stage + backdrop + sound + variable) is ~25 min. Steps 5–6 (the two scripts) ~40 min. Step 7 (testing) ~15 min. Buffer ~10 min for tuning.
This is the last "build" stage. Stage 10 is the finale + course wrap. Mention to campers: "Tomorrow you finish the game and we look at how you did across all five days."