- Learnt27 min · create clone, when I start as a clone, delete this clone
- Basic25 min · rebuild Cat vs Bat with clones
- Challenge 1–327 min · clone them, randomise the count, start the Shark Game
- Extrabonus · they keep coming
Review — where we got to 5 min
Last lesson you made things unpredictable.
pick random (1) to (10)is an oval block, and ovals go inside other blocks’ holes.- Pointing and moving keeps a steady speed; gliding does not.
if on edge, bouncegets its own stack when the movement loop is long.
Quick-fire
You have six bats and you find a bug in the flying script. How many times do you fix it?
Reveal the answer
Six. Every duplicate carries its own copy of the script, and they do not stay in step. That is the problem today’s lesson solves.
Today’s Topic 3 min
- Creating clones
- What is really happening when a clone is made
- Controlling how many there are
Learning outcome
By the end of this lesson you will be able to:
- Make many copies of a sprite from one script.
- Say what the real sprite does and what its clones do.
- Change the number of copies by changing one number.
Learnt — one sprite, many copies 27 min
Three new blocks
All three live in Control, at the bottom.
| Block | What it does |
|---|---|
create clone of [myself v] | Makes one copy, right now, in the same place, with the same everything. |
when I start as a clone | A hat block. Every new copy runs whatever is under it. |
delete this clone | The copy stops existing. Not hidden — gone. |
The real one and the copies
This is the idea that makes clones click, and it is worth saying slowly.
The sprite in your Sprite panel is the real one. It runs the when flag clicked stacks. Its job today is to hide itself and make copies — nothing else.
The clones run the when I start as a clone stacks. They do all the flying, all the sensing, all the being caught.
when flag clicked
hide
repeat (8)
create clone of [myself v]
end
when I start as a clone
show
go to [random position v]
forever
point in direction (pick random (-180) to (180))
repeat (pick random (10) to (20))
move (4) steps
next costume
wait (0.05) seconds
end
end
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
Every clone gets its own everything
Each copy has its own position, its own direction, its own costume, its own size. They all run the same script, but the script asks for random numbers — so no two copies do the same thing.
This is what duplicating could never give you neatly. Six duplicated sprites are six separate things to keep in step. Six clones are one script.
How many? Change one number.
The count lives in the repeat (8). Want twelve instead of eight? Change the 8. Want a surprise? Put a pick random in it.
when flag clicked
hide
repeat (pick random (5) to (14))
create clone of [myself v]
end
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
delete this clone, not hide
When a clone is caught, use delete this clone rather than hide.
- A hidden clone is still there, still running its scripts, still costing work.
- A deleted clone is finished. The Stage genuinely empties.
And there is a bonus: you never need a show at the top again. Clones are made fresh on every green flag, so there is nothing left over from last time.
Basic — Cat vs Bat, with clones 25 min
Open your Topic 1.9 project. You are about to delete five sprites and lose nothing.
How to use this: Click the green flag, then click the stage once and use the arrow keys. The space bar does something as well — find out what.
Step 1 — delete the duplicates
Right-click and delete five of your six bats. Keep one. This feels wrong and is correct.
Step 2 — change the hats
On the bat that is left, change every when flag clicked to when I start as a clone.
Step 3 — the maker stack
Add one new stack: when flag clicked, hide, then repeat (6) holding create clone of [myself v].
Step 4 — test
Press the flag. Six bats, all flying, all bouncing. One sprite in the panel.
Step 5 — delete instead of hide
In the getting-caught stack, replace hide with delete this clone. Then take out the show — clones do not need it.
Step 6 — change the number
Change the 6 to a 20 and press the flag. Twenty bats, and you did not add a single sprite. Change it back to something playable.
There is one extra bat that never moves.
That is the real sprite. Its flag stack is missing the hide.
Nothing appears at all.
Your flying script is still on a when flag clicked hat, so the clones have nothing to run. Every stack the clones need starts with when I start as a clone.
Clone your game
Take any game you have already built with duplicated sprites — the viruses, the bats, whichever — and rebuild it with clones.
The game should play exactly the same. The Sprite panel should look completely different.
Done when: your game plays as it did before, your Sprite panel has one enemy sprite in it instead of six, and changing one number changes how many there are.Nobody knows how many
Make the number of enemies random, between about 8 and 20.
Then make each clone different from the others too: a random size, a random speed. Same script, different creatures.
Done when: three rounds in a row have three different numbers of enemies, no two enemies in a round look the same, and it is all one script.Teacher note
The randomness has to be inside the when I start as a clone stack, not the maker stack. Put it in the maker and every clone gets the same “random” value, because it was picked once before any of them existed. That is a genuinely good bug to have to think about.
Start the Shark Game
A new game, and the one you finish over the next two lessons. Your teacher will give you the shark and the sea; the fish come from the Scratch library.
- Shark at 60%, fish at 30%, backdrop full screen.
- Arrow keys drive the shark. It starts in the middle.
- Space pressed: shark-bite. Not pressed: shark-swim.
- Left arrow faces it left, right arrow faces it right.
- Between 12 and 20 fish, spawned randomly, moving randomly at a steady speed.
- A fish disappears only when it meets an open mouth.
- At least four different kinds of fish, in roughly equal numbers.
- Fish bounce off the edges.
Teacher note
This is the deck’s Mission 1 at its 70 Adcoins, and it is deliberately most of a game. Everything in it has already been taught — this lesson’s clones, Topic 1.9’s random flight, Topic 1.7’s controller. Nobody should need a new block.
Four kinds of fish means four sprites, each cloning three to five times. That is the honest answer at this stage, and it is worth pointing out that the four scripts are identical except for the costume.
They keep coming
So far all your clones are made at the start. Make them arrive while you play instead — a new one every few seconds, for as long as the game runs.
Now clearing the Stage is not the end of the game. Surviving is.
Summary 5 min
create clone of [myself v]makes a copy. The copy runs whatever is underwhen I start as a clone.- The real sprite hides and makes copies. The clones do everything else.
- Every clone has its own position, size and direction — one script, many creatures.
- The number of clones is one number in a
repeat (8). Put a pick random in it and no two games are alike. delete this clone, nothide. A deleted clone is finished; a hidden one is still working.
- Clone
- A copy of a sprite made while the project is running.
- The real sprite
- The one in the Sprite panel. It makes the clones; usually it hides itself.
- Spawning
- Making new things appear in a game while it is being played.
Hand in
Share your project and send the link to your teacher. Missions you finish at home count too — bring the link to the next class and claim your Adcoins.