- Learnt28 min · shared vs sprite-only, and the quiet bug
- Basic24 min · its own speed, size and colour
- Challenge 1–327 min · wobble, big-and-slow, a race
- Extrabonus · a shoal of thirty
Review — last lesson 5 min
create clone of [myself v]makes a copy; the copy runswhen I start as a clone.- Hide the original. It is the spawner.
- Every clone needs
delete this clone, or the project silts up. - Scratch stops at 300 living clones and says nothing about it.
Quick-fire
Your reef had twenty-six bubbles and every one of them rose at exactly 5 steps a tick. It looked wrong. What was missing?
Reveal the answer
Variety — and the reason you could not add it is the whole of today. A variable is normally one box shared by everybody, so “each bubble’s speed” had nowhere to live.
Today’s Topic 3 min
- For all sprites — one box, shared by everything
- For this sprite only — one box per clone
- Why the shared version breaks so quietly
- Giving each bubble its own speed, size, wobble and colour
Learning outcome
By the end of this lesson you will be able to:
- Choose the right kind of variable for a job, and say why.
- Give every clone its own values so a crowd looks natural.
- Recognise a shared-variable bug from the way it looks on screen.
Learnt — one box, or one each 28 min
1 · The dialog you have been clicking past
Every time you make a variable Scratch asks a question, and until now the answer has not mattered:
- For all sprites — one box in the whole project. Every sprite and every clone reads and writes the same box.
- For this sprite only — the box belongs to the sprite. And here is the part that matters: every clone gets its own copy of it.
Scores, lives and timers are shared — there is only one game. Anything that describes one bubble must be sprite-only.
2 · Watch the shared one break
Here is a reef where speed was made for all sprites. Every clone sets it as it is born:
when I start as a clone
set [speed v] to (pick random (2) to (8))
show
repeat until <(y position) > (165)>
change y by (speed)
end
delete this clone
speed box, so the newest clone decides the speed for all of them.How to use this: Click the green flag. Watch how the bubbles drift into a row and move as one sheet.
3 · The fix is one dropdown
Delete speed and make it again — same name, same blocks — choosing For this sprite only. Not one block changes. The behaviour changes completely:
How to use this: Click the green flag. Same eight bubbles, same script — but now each keeps its own speed.
4 · What a clone inherits
When a clone is born it takes a snapshot of the sprite:
- position, direction, size, costume, effects — copied
- sprite-only variables — copied, then independent
- shared variables — not copied, because there is only one
That snapshot is useful: set the costume in the spawner before the clone block and each bubble is born the right colour already.
Basic — its own everything 24 min
Open last lesson’s reef. You are giving each bubble a character of its own.
Step 1 — the variables
- Make
speed— for this sprite only. - Make
wobble— for this sprite only. - Keep
bubblesas it is — it counts the whole reef, so it is shared. - Untick all three readouts. They cannot show you a clone’s copy anyway.
Step 2 — roll the dice as it is born
- At the top of the clone script, set
speedto a random 2 to 8. - Set
wobbleto a random 1 to 4. - Add
set size to (pick random (25) to (60)) %.
Step 3 — use them in the rise
- Change the rise from
change y by (5)tochange y by (speed). - Add a sideways drift:
change x by (wobble)inside the same loop. - Put
if on edge, bounceafter it so a drifting bubble turns back.
Step 4 — colour it in the spawner
- In the spawner, before the clone block:
switch costume to (pick random (1) to (5)). - Run it. Twenty bubbles, no two alike.
when I start as a clone
set [speed v] to (pick random (2) to (8))
set [wobble v] to (pick random (1) to (4))
set size to (pick random (25) to (60)) %
change [bubbles v] by (1)
show
repeat until <(y position) > (165)>
change y by (speed)
change x by (wobble)
if on edge, bounce
end
change [bubbles v] by (-1)
delete this clone
How to use this: Click the green flag and watch for ten seconds. Pick one bubble and follow it up.
They still all move at the same speed.
speed is still shared. The dropdown cannot be changed later — delete the variable, make a new one with for this sprite only, and reattach it in both places.
They rise at the same speed as each other, but that speed keeps jumping about.
Same bug, seen from the other side. The jumping value is each new clone overwriting the one shared box.
They all drift the same way and pile up on one side.
wobble is shared, or it is set in the spawner rather than in the clone script.
Some bubbles never move at all.
pick random (0) to (8) can roll a 0. Start the range at 1 or 2.
A proper wobble
A straight diagonal is not a wobble. Make them weave.
- Each bubble has its own
wobbleand its own drift direction. - The drift reverses every so often, so the path snakes.
- No two bubbles weave in step with each other.
How to use this: Click the green flag and follow one bubble with your eye. It weaves; its neighbour weaves differently.
Teacher reveal — the flip
change x by (wobble)
change [tick v] by (1)
if <(tick) > (12)> then
set [wobble v] to ((0) - (wobble))
set [tick v] to (0)
end
tick must also be sprite-only, or every bubble flips on the same beat and you are back to lockstep. That is a good second demonstration of today’s rule.
Big and slow
Stop rolling speed separately. Work it out from the size, so a big bubble is always a slow one.
- Size is rolled once, per bubble.
- Speed is calculated from it, not rolled.
- A big bubble is visibly slower than a small one, every single run.
How to use this: Click the green flag. Watch a small bubble overtake a big one on the way up.
Teacher reveal — deriving one from the other
set [my size v] to (pick random (25) to (60))
set size to (my size) %
set [speed v] to (round ((9) - ((my size) / (10))))
The round is not decoration — without it a bubble rises at 4.800000000000001 steps and a readout of it looks broken. Worth showing both ways.
Bubble race
Five bubbles in five lanes. Find out which one wins.
- Five clones at fixed x positions, evenly spread.
- Each has its own speed and its own lane number.
- The first to the surface announces its lane, and the others do not overwrite it.
How to use this: Click the green flag. Five lanes go up at once and the winner's lane number appears.
Teacher reveal — why second place does not overwrite the winner
if <(winner) = (0)> then
set [winner v] to (lane)
end
lane is sprite-only, winner is shared, and the guard is what makes “first” mean first. Both kinds of variable in four blocks — a good place to stop and name them out loud.
A shoal of thirty
Put everything together and fill the reef. Thirty bubbles, each with its own speed, size, wobble and colour — and no lockstep anywhere.
- Thirty made, comfortably under the 300 ceiling.
- Four things rolled per bubble, all sprite-only.
- The shared counter still returns to 0 at the end.
How to use this: Click the green flag and let it run. Try to pick out two bubbles doing the same thing.
Teacher note
This is the pay-off for the whole lesson, and it is worth saying plainly: the script is barely longer than last lesson’s. The richness came from the radio button, not from more code.
Summary 5 min
- For all sprites = one box for the project. Scores, lives, timers.
- For this sprite only = one box per clone. Speed, size, wobble, lane.
- A crowd that moves in lockstep is a shared variable. That is the symptom to learn.
- Scratch shows only the original’s copy of a sprite-only variable, so you debug these by watching the Stage.
- A variable cannot be converted. Delete it and make a new one.
- Global variable
- “For all sprites” — one box shared by everything.
- Sprite-only variable
- “For this sprite only” — and every clone gets its own copy.
- Lockstep
- When many clones move identically because they share a value.
- Inherit
- What a clone copies from the sprite at the moment it is born.
Hand in
Save your shoal. Next lesson you start popping them — and the score turns out to need both kinds of variable at once.