Learning Goals 3 min
By the end of this lesson you will be able to:
- Build a spawner that uses create clone of (myself v) on a timer to make new stars appear at random x positions along the top of the Stage.
- Write a per-clone fall script under when I start as a clone that gives each star its own random speed and fades it as it falls using change [ghost v] effect by ().
- Use a (count) variable as a population cap — only spawn when fewer than 50 clones exist, and decrement on delete this clone.
Warm-Up — predict the snowstorm 7 min
Aisyah is trying to make a "snow" effect using one Snowflake sprite and clones. She writes this on the original sprite:
when flag clicked
forever
create clone of (myself v)
end
And under when I start as a clone, each snowflake does nothing — no movement, no hide, nothing. She clicks the flag. Predict — what happens?
Reveal the answer
The forever loop fires thousands of times a second. Within a second or two, Scratch hits its 300-clone limit and silently refuses to spawn any more. The Stage shows a giant pile of motionless snowflakes stacked on top of the original sprite. The project runs at 4 frames per second because Scratch is exhausted. Aisyah's missing three things — a wait to slow the spawner down, a fall script so clones actually move, and a delete this clone so old clones go away. Today we build all three, plus a count cap so we never even reach Scratch's 300 limit.
This whole lesson is the Cluster D capstone — every cloning idea you've met (spawn-on-timer, when-I-start-as-a-clone, per-clone variables, delete this clone, counting clones) shows up in one beautiful effect.
New Concept — the spawn / live / die pattern 15 min
Every clone effect in Scratch — bullets, raindrops, sparks, enemies, falling stars — follows the same three-part pattern. Once you can name the three parts, you can build any of them.
Part 1 — the spawner (original sprite)
The original sprite (the one you drag onto the Stage) doesn't fall. Its job is to hide itself, then run a forever loop that waits a moment and then calls create clone of (myself v). The wait sets the spawn rate.
when flag clicked
hide
set [count v] to (0)
forever
wait (0.3) seconds
if <(count) < (50)> then
create clone of (myself v)
end
end
Part 2 — the per-clone life script
Under when I start as a clone, each new clone runs its own copy of a script. This is where it picks its random x, its random speed, shows itself, and falls.
Two things to notice about per-clone scripts:
- Every clone has its own copy of every variable if you make those variables "For this sprite only". So
fallas a sprite-only variable means each star can have a different speed. - The change [count v] by (1) at the very top is what keeps the cap honest — it tells the spawner "I exist, count me".
Part 3 — the death (delete this clone)
Clones that never die pile up forever. The fix is one block at the bottom of the per-clone script: delete this clone. Right before it, decrement the count, otherwise the count drifts upward and eventually freezes the spawner.
change [count v] by (-1)
delete this clone
The fade — change ghost effect by 3
The ghost effect is a number from 0 (fully visible) to 100 (invisible). Inside the fall loop, change [ghost v] effect by (3) nudges the star a little more transparent every frame. By the time it reaches the bottom, it's almost gone — a soft, atmospheric fade.
Worked Project — build the cloud in ten steps 15 min
Open Scratch. Delete the cat. Choose a dark backdrop — Stars or Space from the library. Add the Star sprite from the library (or paint your own — a small yellow blob is fine).
Step 1 — Make the variables
From Variables, click Make a Variable. Name it count and choose For all sprites. Untick its Stage checkbox (we don't want to see it on the final project). Then make another variable, name it fall, and choose For this sprite only — this is critical.
Step 2 — Shrink the star
Select the star sprite and set its size to about 30. From Looks: set size to (30) %. (You can drag this block in once and run it to set the costume size, then throw it away.)
Step 3 — Build the spawner
On the original star sprite, build:
when flag clicked
hide
set [count v] to (0)
forever
wait (0.3) seconds
if <(count) < (50)> then
create clone of (myself v)
end
end
Step 4 — Start the clone's life
Underneath, drag in when I start as a clone. This hat fires once for every new clone, on that clone's body.
Step 5 — Count, then position
The first thing each new clone does is bump the count and jump to a random spot along the top of the Stage:
when I start as a clone
change [count v] by (1)
go to x: (pick random (-220) to (220)) y: (180)
set [fall v] to (pick random (2) to (5))
set [ghost v] effect to (0)
show
Step 6 — Fall and fade
Add the fall loop directly below — a repeat until that runs until the star drops off the bottom of the Stage:
repeat until <(y position) < (-180)>
change y by ((0) - (fall))
change [ghost v] effect by (3)
end
fall speed, fade a little more. The minus-sign trick — 0 − fall — lets us reuse a positive variable for downward motion.Step 7 — Die properly
The last two blocks of the per-clone script. Decrement first, then delete:
change [count v] by (-1)
delete this clone
Step 8 — Click the flag
You should see a steady, gentle drift of stars from top to bottom, each one fading as it falls. Around the 15-second mark, you'll have roughly 50 stars on screen and the spawner pauses — exactly what we want.
Step 9 — Polish
Try swapping the wait time (0.3 → 0.1 for a blizzard, → 1 for a gentle drizzle), the cap (50 → 100 for chaos), and the fade rate (3 → 1 for slow fade, → 8 for sudden fade). Add set size to (pick random (15) to (50)) % inside the clone hat for varied depths.
Step 10 — The full assembled project
All on one sprite — the Star. Two scripts total.
when flag clicked
hide
set [count v] to (0)
forever
wait (0.3) seconds
if <(count) < (50)> then
create clone of (myself v)
end
end
when I start as a clone
change [count v] by (1)
go to x: (pick random (-220) to (220)) y: (180)
set [fall v] to (pick random (2) to (5))
set [ghost v] effect to (0)
show
repeat until <(y position) < (-180)>
change y by ((0) - (fall))
change [ghost v] effect by (3)
end
change [count v] by (-1)
delete this clone
What you just built: the exact same pattern that powers raindrops in a rain effect, bullets in a shooter, sparks in a fireworks demo, and falling petals in a sakura scene. The "thing" changes — the pattern stays.
Try It Yourself — three remixes 12 min
Goal: Make the stars fall faster. Change one number in your project so the slowest stars drop at speed 5 and the fastest at speed 10.
set [fall v] to (pick random (5) to (10))
Think: A clone's fall is set once at birth and never changes — that's why the fast stars stay fast and the slow stars stay slow. Same idea as giving every enemy in a game a different walk speed.
Goal: Make some stars different sizes. At birth, each clone should pick a random size between 15% and 50%. Tiny stars feel further away; big ones feel close.
when I start as a clone
change [count v] by (1)
go to x: (pick random (-220) to (220)) y: (180)
set [fall v] to (pick random (2) to (5))
set size to (pick random (15) to (50)) %
set [ghost v] effect to (0)
show
Think: If you wanted bigger stars to fall faster (more realistic — close things move past us faster), how would you couple fall to size? Hint: () * ().
Goal: Make each star turn as it falls — a slow lazy rotation. Add turn cw () degrees inside the fall loop. Pick a random turn speed at birth so some stars rotate fast, some slow, some hardly at all.
when I start as a clone
change [count v] by (1)
go to x: (pick random (-220) to (220)) y: (180)
set [fall v] to (pick random (2) to (5))
set [spin v] to (pick random (-5) to (5))
set [ghost v] effect to (0)
show
repeat until <(y position) < (-180)>
change y by ((0) - (fall))
turn cw (spin) degrees
change [ghost v] effect by (3)
end
change [count v] by (-1)
delete this clone
spin. Negative values turn anticlockwise — half your stars spin each way.Think: You've now got three things that vary per clone — fall, size, spin. Each one feels alive because each star is a little different.
Mini-Challenge — Daniel's mystery freeze 5 min
"The spawner that quit early"
Daniel built the falling stars project, but his spawner stops creating new stars after about 30 seconds — the screen empties and stays empty. The stars he did spawn fall and disappear normally. He shows you his per-clone script:
when I start as a clone
change [count v] by (1)
go to x: (pick random (-220) to (220)) y: (180)
set [fall v] to (pick random (2) to (5))
set [ghost v] effect to (0)
show
repeat until <(y position) < (-180)>
change y by ((0) - (fall))
change [ghost v] effect by (3)
end
delete this clone
change [count v] by (-1)
What's gone wrong? Why does the spawner go silent after a while?
Reveal one valid solution
delete this clone stops the script the instant it runs. The very next block — change [count v] by (-1) — never executes. So every clone increments count at birth, but no clone ever decrements it at death. After about 50 stars have fallen, count reaches 50 and the spawner's (count) < (50) check is permanently false. The spawner never spawns again.
The fix is to swap the last two blocks — decrement first, then delete:
change [count v] by (-1)
delete this clone
Lesson: "Delete" is a wall, not a doorway. Anything you need to do at death has to happen before the delete block. This is the most common cloning bug in the world — even professional game devs hit it the first few times.
Recap 3 min
You shipped the Cluster D capstone. A single sprite, two scripts, eighteen blocks, and an effect that genuinely looks like a piece of generative art. You used every idea from this cluster: create clone of (myself v) on a timer, when I start as a clone as a per-clone life script, sprite-only variables so each clone keeps its own fall speed, a (count) variable as a population cap, and delete this clone with the decrement before it. Spawn, live, die, count. That's it. From here, the same pattern builds bullets, raindrops, enemies, sparks — anything that appears, behaves, and goes away.
- Spawner
- The original sprite whose only job is to hide itself and call create clone of (myself v) on a timer. It doesn't fall, fade, or do anything visible — the clones do all the work.
- Per-clone variable
- A variable made with the "For this sprite only" option. Every clone gets its own private copy. That's how each falling star can have a different
fallspeed without overwriting its neighbours. - Population cap
- A maximum number of live clones, enforced by an if <> then around the create clone call. Protects against Scratch's hidden 300-clone hard limit and keeps the project smooth.
- Ghost effect
- A Looks effect from 0 (fully visible) to 100 (invisible). change [ghost v] effect by () nudges it up by a fixed amount every frame, producing a soft fade-out.
- Decrement-before-delete
- The rule that any clean-up — counting, broadcasting, saving — must happen before the delete this clone block, because delete halts the script instantly.
Homework 2 min
Reskin the cloud. Take your finished Falling Stars project and turn it into something else by changing the costume and a couple of numbers. Keep the spawn / live / die pattern intact.
- Pick a theme: rain, snow, sakura petals, falling leaves, glitter, or your own idea. Replace the star costume with a sprite that fits the theme. (Library or your own paint.)
- Tune three numbers to match the feel: the spawn wait () seconds, the
fallrange, and the fade rate (the number inside change [ghost v] effect by ()). Snow is slow. Rain is fast and barely fades. Petals drift. - Add one new sprite-only twist of your own — size, rotation, colour effect, costume switching. Anything per-clone.
Save as HW-L3-25-Cloud-Reskin.sb3.
Bring back next class:
- The
.sb3file with your reskin. - One sentence: "My count cap is set to ___ because ___." (No wrong answers — just explain your reasoning.)
Heads up for next class: SCR-L03-26 kicks off Cluster E — Game State Machines. We meet the idea that a real game has phases (title screen, playing, paused, game over) and that one variable can control all of them. No live coding next class — pure concept. Bring brain.