Stage 7: Bring the Clones to Life
Keep your Scratch project tab open all week. Open in a new tab so you don’t leave the course.
a clone behavior script — random size, color, direction, and gliding motion
how each clone picks its own life when it's born
a swarm of fish that actually swims across the screen
This is the densest single script in the course. Move slow. Show the whole thing end to end before campers touch their laptops:
- Click the Fish sprite. Drag in when I start as a clone.
- Random costume: an if/else with
pick random 1 to 2 = 1— switch costume to fish-b or fish-c. - Random color effect:
set color effect to (pick random 1 to 100). - Random size:
set enemySize to (pick random 5 to (playerSize + 20))thenset size to enemySize %. - Random side and direction: if/else picks left side (
set x -300, point in direction 90) or right (set x 300, point in direction -90). - Random Y:
set y to (pick random -140 to 160). - Show, wait 0.25 sec, glide:
glide (pick random 4 to 8) secs to x: (0 - x position) y: (y position). - Delete this clone.
Click the green flag. The swarm comes alive. Different colors, sizes, paths. That's the magic moment.
The big idea
Yesterday the clones spawned in a pile. Today each clone wakes up and decides who it is — what costume, what color, what size, where to start, which way to glide, how fast to move. The swarm goes from a heap to a school.
The new block is when I start as a clone. It runs once, when a clone is born. Whatever code comes after it is the clone's first thoughts — the choices that define its short life.
create clone of myself ─→ a new clone is born
│
▼
when I start as a clone:
- pick costume
- pick color
- pick size (relative to player)
- pick spawn side and direction
- pick Y position
- show, glide across, delete
Each clone runs through this script independently. Clone A starts on the left side, small, yellow. Clone B starts on the right side, big, purple. They never know about each other — they each live their own life.
The cleverest piece is that the size is RELATIVE to the player. We pick enemySize from 5 to playerSize + 20. As the player grows, the swarm gets bigger too. Some clones are always smaller than the player (eatable), some are always bigger (dangerous). The game scales as you do.
- when I start as a clone
- an event block that runs once, when a clone is born
- color effect
- a Looks effect that shifts the sprite's color
- glide
- a smooth motion block that moves the sprite from one position to another over time
- delete this clone
- remove this clone from the game completely
- if/else
- a Control block — runs one set of blocks if a condition is true, otherwise runs the else set
Stage 6 should be done — the Fish template hides itself and spawns a new clone every 1–2 seconds.
Build it
This is one long script. Build it in pieces, testing as you go.
Step 1 — Add the when-I-start-as-a-clone event
In the Fish sprite's code area (separate from your Stage 6 spawn script), drag in when I start as a clone from Control.
This block is the entry point for every clone's life.
Step 2 — Random costume
Drag an if/else block under the event. Inside the diamond, build a question:
- From Operators, drag the
=(equals) block. - On the left side, drag pick random (1) to (2).
- On the right side, type 1.
The question now reads: "is a random number from 1 to 2 equal to 1?" This is a coin flip.
In the if body, add switch costume to (fish-b).
In the else body, add switch costume to (fish-c).
So half of the clones become yellow stripey, half become purple. The swarm has visual variety.
Step 3 — Random color effect
Outside the if/else (still inside the when-I-start-as-a-clone script), add set (color) effect to (pick random (1) to (100)).
The set (color) effect block is from Looks. The dropdown lets you pick which effect — choose color. Each clone now also picks a random color shift, so even two fish-b clones look slightly different.
Step 4 — Random size relative to player
This is the smartest part of the script. Each clone's size is picked relative to the player's current size — so the game scales as you grow.
Add set enemySize to (pick random (5) to (playerSize + 20)).
How to build it:
- From Variables, drag set (enemySize) to (0).
- From Operators, drag pick random (1) to (10).
- Drop pick random into the set enemySize slot.
- Change the first number to 5 (smallest possible enemy).
- For the second slot, drag the
+Operators block. - Put playerSize (from Variables) on the left of the
+. - Put 20 on the right.
The full line: set enemySize to (pick random (5) to (playerSize + 20)).
Right after that, add set size to (enemySize) %. This applies the random number to how big the clone looks on stage.
Step 5 — Random spawn side and direction
We want some clones to come from the left, some from the right. Coin flip again.
Add another if/else block. Inside the diamond, build the same coin-flip question (pick random 1 to 2 = 1).
In the if body:
set x to (-300)
point in direction (90)
In the else body:
set x to (300)
point in direction (-90)
A -300 x-position is far off the left edge of the stage. Pointing in direction 90 means facing right (so the clone faces into the stage). The else side mirrors: spawn off the right edge facing left.
Step 6 — Random Y position
Add set y to (pick random (-140) to (160)).
The stage is roughly 180 units tall and 240 wide. -140 is near the bottom; 160 is near the top. Every clone picks a different Y, so the swarm spreads out vertically.
Step 7 — Show, wait, glide, delete
The clone is set up. Time to bring it on stage:
Clone behavior script
when I start as a clone if <(pick random (1) to (2)) = (1)> then switch costume to [fish-b v] else switch costume to [fish-c v] end set [color v] effect to (pick random (1) to (100)) set [enemySize v] to (pick random (5) to ((playerSize) + (20))) set size to (enemySize) % if <(pick random (1) to (2)) = (1)> then set x to (-300) point in direction (90) else set x to (300) point in direction (-90) end set y to (pick random (-140) to (160)) show wait (0.25) seconds glide (pick random (4) to (8)) secs to x: ((0) - (x position)) y: (y position) delete this clone
Notes on these blocks:
- show — make the clone visible. (The template was hidden in Stage 6; clones start hidden too unless we show them.)
- wait 0.25 seconds — gives the player a moment to see the clone before it starts moving.
- glide — smoothly moves the clone from its current position to the destination over a random 4–8 seconds. The slower glides are easier targets; faster ones are harder.
- 0 - x position — this is clever math. If the clone started at
-300(left side),0 - (-300)=+300(the right side). The clone glides ALL THE WAY ACROSS the stage. The y position stays the same. - delete this clone — once it's done gliding (off the other side), remove it cleanly. Without delete, dead clones pile up and slow Scratch.
Step 8 — Test the swarm
Click the green flag. Wait a moment.
Clones should now:
- Spawn from random sides
- Show up at random Y heights
- Have different costumes and colors
- Glide across the screen at different speeds
- Disappear when they reach the far side
The swarm is alive.
Save your project.
Understand it
The most important pattern today is per-clone setup. Every clone runs the same script, but pick random makes each clone's choices different. Pros call this parametric variation: same template, randomized parameters. The same trick powers procedurally generated levels in real games.
The reason we use pick random 5 to (playerSize + 20) for the size is adaptive difficulty. If we picked from a fixed range (say 5 to 200), early game with a tiny player would be impossible (everything's bigger). Late game with a 90% player would be too easy (nothing's bigger). By scaling the upper bound with playerSize, the game always has some eatable enemies and some dangerous ones. The challenge stays balanced.
The glide block vs change x by 1 in a loop: both make a sprite move, but glide is time-based while a loop is frame-based. A glide of "8 seconds" takes exactly 8 seconds regardless of how fast the computer is. A change x by 1 loop runs faster on faster computers. For motion that needs to feel consistent across devices, glide wins. Real games use this distinction too.
The delete this clone at the end is critical. Without it, every clone that finishes gliding stays at the destination forever. Scratch's 300-clone cap means new clones stop spawning after 300 — and the game stalls. Cleaning up old clones is the same idea as cleaning up old turtles in Python Arcade: let no orphan clone live.
The 0 - x position trick is worth slowing down on. If a clone spawned at x = -300 (left side), 0 - (-300) = 300, so the glide goes to the right side. If it spawned at 300, 0 - 300 = -300, so it glides to the left. The clone always exits the opposite side. One line of math handles both cases.
Try this
Try this
Three short experiments. Predict before you run, then test your guess.
Remove the delete this clone line at the end. Click the green flag. Predict what happens after 30 seconds. Try it. Did Scratch slow down? Put the block back when you're done.
Change set enemySize to (pick random (5) to (playerSize + 20)) to set enemySize to 30. Now all clones are size 30. Click the green flag. Is the game more or less fun with no size variety?
Stage 8 is the EATING moment. The player decides whether a clone is food (smaller) or danger (bigger). What two variables does the eating-check need to compare?
Test your stage
- Clicking the green flag makes the swarm appear over time.
- Clones come from both sides of the stage (left and right).
- Clones have different sizes — some small, some bigger.
- Clones have different colors — visual variety.
- Clones glide smoothly across the screen and disappear on the other side.
- Your project doesn't slow down even after 60 seconds of play.
- Design check. Watch for 30 seconds without playing. Does the swarm feel like a school of fish or like clones piling up? If the second one, double-check the delete this clone block.
If it breaks
- All clones are the same costume. The if/else block at the start probably isn't snapping in correctly. The block needs a single condition (the equals-block with pick-random) in its diamond slot. If the condition is empty, neither branch runs.
- All clones are the same size. Two suspects. First, the set enemySize block may have a constant instead of
pick random. Second,set size to (enemySize) %may be missing — without it, the random number gets stored but never applied to the actual sprite size. - Clones are way bigger than the screen.
playerSize + 20got very large becauseplayerSizehas grown. That's correct game design — late-game enemies should be bigger. If it feels too extreme, tryplayerSize + 10or even just a constant range like5 to 100. - Clones spawn but never move. The glide block is missing or in the wrong place. It should be after
showandwait 0.25. Drag it in fresh if needed. - Clones spawn on top of each other in the middle of the stage. The if/else for x position probably didn't run. Check that the diamond has the pick-random-1-to-2 equals 1 condition, and both branches have x and direction blocks.
- The game keeps slowing down. delete this clone is missing from the end of the script. Add it as the very last block.
This is the longest, densest single script of the course. The book lays it out in one panel, but for kids 7–9 that's overwhelming. Build it in the 7 steps above — test after every 2-3 steps.
The single most common failure: an empty if/else diamond. Kids drag the if/else, then forget to drop the pick-random-equals-1 condition into the diamond. Both branches silently fail. Walk the room and confirm every if/else has a visible blue/green block in the diamond.
The second most common: dropping the set enemySize block without filling in the random ranges. They leave it as the default set enemySize to 0. All clones become invisible (size 0%). The fix: check that the slot is filled with a pick random (5) to (playerSize + 20) shape.
Plan a snack break at minute 50. The last 40 minutes are testing + tuning the swarm.
If a camper finishes by minute 70, push them into the medium stretch (tuning). The hard stretch (rare giant) is great preparation for Stage 8's collision logic — but it adds a third if/else nest, which is real engineering. Reserve it for confident kids.
The "0 - x position" math is genuinely advanced for ages 7-9. Don't dwell on it. Just say "this number subtracts where the clone started from zero, which means it goes to the other side" and move on.