power-ups list. The list is the menu; the brick decides when to drop; the paddle decides what to do when it catches one.Learning Goals 3 min
By the end of this lesson you will be able to:
- Use a Scratch list as a "menu of choices" — a named bag of strings that a script can pick from at random.
- Combine pick random (1) to (10) with if <> then to make events happen only sometimes — a 1-in-5 chance, a 1-in-10 chance.
- Spawn a falling power-up clone from a destroyed brick, give that clone a random power-up-type, and apply different effects (long-paddle, sticky-ball, extra-life) when the clone touches the paddle.
Warm-Up — same bricks every time 7 min
Your Breakout from the previous lesson works. Paddle moves with the mouse, ball bounces off bricks, bricks delete when hit. But play it three times. Every game is identical. No surprise, no reason to keep playing past round one.
Predict puzzle. Imagine a brick's destroy-script looked like this:
when I receive (brick-hit v)
change [score v] by (10)
if <(pick random (1) to (5)) = (1)> then
create clone of (PowerUp v)
end
delete this clone
If a level has 40 bricks, roughly how many power-ups will the player see in one round? And what happens to that average if you change the 5 to a 10?
Reveal the answer
1-in-5 means about 8 power-ups per 40-brick level (40 ÷ 5 = 8). Some rounds you'll get 5, some rounds you'll get 11 — that's randomness, not a bug. Change 5 to 10 and the rate halves to roughly 4 per level. The denominator is the rarity knob — turning it up makes power-ups rarer and therefore more exciting when they appear.
Today you'll add the randomness, the falling clone, and a list of three different power-ups so each drop is also a surprise about which one.
Second predict. What's the difference between these two diamond questions?
if <(pick random (1) to (5)) = (1)> then
...
end
if <(pick random (1) to (5)) < (2)> then
...
end
Reveal the answer
They mean the same thing. pick random (1) to (5) returns 1, 2, 3, 4, or 5 with equal chance. Asking = 1 hits 1 of those 5 values. Asking < 2 hits only 1 as well — same one value. Both fire 1-in-5. Style choice: = 1 reads more clearly, so we'll use it everywhere today.
New Concept — lists as menus of choices 15 min
You met lists in L04-28 as "rows of data" — high scores, names, inventory items. Today we use a list for a different purpose: as a menu of choices a script can pick from at random. Three power-ups means a list with three items. Want a fourth power-up tomorrow? Add an item. The script that picks doesn't change.
Making the list
Variables palette → Make a List → name it power-ups. Tick the For-all-sprites bullet so the PowerUp sprite and the Brick sprite both see it. Now add three items by hand using the list display on the Stage (click the + at the bottom-left):
long-paddlesticky-ballextra-life
That's it. No script needed. The list lives in the project and remembers its items every time you re-open the file.
Picking a random item
The block we need is in the Variables palette once you create a list:
set [power-up-type v] to (item ((pick random (1) to (length of [power-ups v]))) of [power-ups v])
The clever bit is length of [power-ups v]. If your list has 3 items, the range is 1 to 3. Add a fourth item, the range automatically becomes 1 to 4 — without editing the script. The list itself is the configuration.
Two layers of randomness
Power-ups have two separate dice rolls:
- Should this brick drop one? — handled by pick random (1) to (5) at the moment the brick is destroyed. About 1-in-5 bricks become drop-bricks.
- Which power-up? — handled by the list pick at the moment the power-up clone is born. Each spawn picks one of long-paddle / sticky-ball / extra-life with equal chance.
Keep these two rolls separate. The brick decides if a power-up exists at all. The power-up decides what it is.
Per-clone variables
The PowerUp sprite has many clones falling at once. Each clone needs to remember its own type — so when it touches the paddle, the paddle reaction knows what to apply. The trick: power-up-type must be a For this sprite only variable, not a global one. Each clone gets its own copy.
when I start as a clone
set [power-up-type v] to (item ((pick random (1) to (length of [power-ups v]))) of [power-ups v])
switch costume to (power-up-type)
show
forever
change y by (-3)
if <touching (Paddle v) ?> then
broadcast (apply-power-up v)
delete this clone
end
if <(y position) < (-170)> then
delete this clone
end
end
Worked Example — bricks that drop surprises 20 min
Open your Breakout project from L04-33. We're going to add a PowerUp sprite and modify the Brick destroy-script.
Step 1 — Create the power-ups list
Variables palette → Make a List. Name: power-ups. For-all-sprites. Add three items via the Stage display: long-paddle, sticky-ball, extra-life. Click the eye icon to hide the list from the Stage when you're done.
Step 2 — Paint the PowerUp sprite
New sprite → Paint. Make three costumes, named exactly long-paddle (a long blue capsule), sticky-ball (a yellow blob), extra-life (a red heart). Each costume should be small — about 20×20 pixels — so power-ups don't dominate the screen as they fall.
Step 3 — Add the per-sprite type variable
With the PowerUp sprite selected → Variables → Make a Variable. Name: power-up-type. Critical: tick For this sprite only. (If it's For-all-sprites by mistake, every clone shares one type and the system breaks.)
Step 4 — Hide the original PowerUp sprite
The original sprite never appears — only its clones do. On the PowerUp: when ⚑ clicked → hide. One block.
Step 5 — Write the clone behaviour
On the PowerUp sprite, add the clone-life script from the Concept section. when I start as a clone picks the type, switches costume, shows, then a forever loop falls and watches for the paddle.
Step 6 — Modify the Brick destroy-script
On your Brick sprite, find the existing script that runs when the ball hits a brick. Add a random check + spawn before the delete this clone:
when I receive (brick-hit v)
change [score v] by (10)
if <(pick random (1) to (5)) = (1)> then
create clone of (PowerUp v)
end
delete this clone
Step 7 — Position the PowerUp at the brick
Two-step trick. The brick first moves the PowerUp sprite (the original, still hidden) to its own position, then creates the clone. The clone is born at the brick's location:
when I receive (brick-hit v)
change [score v] by (10)
if <(pick random (1) to (5)) = (1)> then
set [drop-x v] to (x position)
set [drop-y v] to (y position)
broadcast (spawn-power-up v)
end
delete this clone
On the PowerUp sprite, add a second hat:
when I receive (spawn-power-up v)
go to x: (drop-x) y: (drop-y)
create clone of (myself v)
Step 8 — Write the apply-power-up handler on the paddle
The clone broadcasts apply-power-up when caught. Now the Paddle sprite reacts:
when I receive (apply-power-up v)
if <(power-up-type) = [long-paddle]> then
set size to (175) %
wait (10) seconds
set size to (100) %
end
if <(power-up-type) = [sticky-ball]> then
set [sticky? v] to [yes]
end
if <(power-up-type) = [extra-life]> then
change [lives v] by (1)
end
Step 9 — Test each power-up in isolation
Hard to playtest randomness. Temporarily change the random check to (pick random (1) to (1)) = (1) — that's "always drop". Then change the list to only long-paddle, play, confirm the paddle stretches. Reset, only sticky-ball, play, confirm sticky? flips. Reset, only extra-life, play, confirm lives increases. This is how you debug random systems — temporarily make them not random.
Step 10 — Restore randomness and play normally
Put the list back to all three items. Put the brick check back to (pick random (1) to (5)) = (1). Click flag. Play three rounds. You should see roughly 6-10 power-ups per round, with all three types showing up about equally often.
The full PowerUp sprite
when flag clicked
hide
when I receive (spawn-power-up v)
go to x: (drop-x) y: (drop-y)
create clone of (myself v)
when I start as a clone
set [power-up-type v] to (item ((pick random (1) to (length of [power-ups v]))) of [power-ups v])
switch costume to (power-up-type)
show
forever
change y by (-3)
if <touching (Paddle v) ?> then
broadcast (apply-power-up v)
delete this clone
end
if <(y position) < (-170)> then
delete this clone
end
end
What you just built: a system where one list controls the entire roster of power-ups. Want a fourth one tomorrow? Add a costume named multi-ball, add the string to the list, add a branch to the paddle's apply handler. Three small edits, no rewrite of the random spawner. Lists are how you stop hard-coding choices into your scripts.
Try It Yourself — three list-driven drills 15 min
Goal: Make a single sprite that says a different random greeting each time you click the flag. The greetings live in a list called greetings with five items: Hi!, Hello!, Hey there!, Apa khabar?, Salam!. No power-up logic — just the list-pick pattern in isolation.
when flag clicked
say (item ((pick random (1) to (length of [greetings v]))) of [greetings v]) for (2) seconds
Think: If you add a sixth greeting to the list later, you don't touch the script at all. The list is the data, the script is the behaviour, and they're independent. This separation is one of the most important ideas in all of programming.
Goal: Turn your power-up drop rate into a difficulty knob. Make a variable power-up-rarity defaulting to 5. The brick's random check uses this variable instead of a hard-coded 5. Add Stage buttons to bump rarity up or down (1 = drop every brick, 20 = very rare).
when I receive (brick-hit v)
change [score v] by (10)
if <(pick random (1) to (power-up-rarity)) = (1)> then
set [drop-x v] to (x position)
set [drop-y v] to (y position)
broadcast (spawn-power-up v)
end
delete this clone
Think: A variable in place of a literal lets you tune the game without re-editing scripts. Most professional game engines work this way — designers tweak numbers, programmers write the systems.
Goal: Add a weighted list. extra-life should be much rarer than long-paddle. Build a list called weighted-power-ups with these items: long-paddle, long-paddle, long-paddle, sticky-ball, sticky-ball, extra-life. Six items total. Same random-pick code as before — but now long-paddle appears 3/6 (50%), sticky-ball 2/6 (33%), extra-life 1/6 (17%).
when I start as a clone
set [power-up-type v] to (item ((pick random (1) to (length of [weighted-power-ups v]))) of [weighted-power-ups v])
switch costume to (power-up-type)
show
forever
change y by (-3)
if <touching (Paddle v) ?> then
broadcast (apply-power-up v)
delete this clone
end
if <(y position) < (-170)> then
delete this clone
end
end
Think: Duplicating a list entry doubles its odds. No probability maths required — the list itself encodes the weights. This is exactly how the loot tables in big commercial games work: rarer items appear fewer times in the master list.
Mini-Challenge — the power-up that won't fall 5 min
"Aisyah's stuck spawner"
Aisyah followed the worked example exactly. Bricks destroy, score increases, and once in a while a power-up does spawn — but it appears at the top-left of the Stage instead of where the brick was. Sometimes two spawn there at once, stacking on each other. Here are her relevant scripts:
when I receive (brick-hit v)
change [score v] by (10)
if <(pick random (1) to (5)) = (1)> then
broadcast (spawn-power-up v)
end
delete this clone
when I receive (spawn-power-up v)
create clone of (myself v)
Why do the power-ups appear in the top-left, and what's the fix?
Reveal one valid solution
The PowerUp sprite has never been told to move. When the project loads, it sits wherever Aisyah last left it in the editor — probably the top-left from when she dragged it onto the Stage to design its costumes. Every clone is born at the parent's current position, so every clone spawns in that same top-left spot, regardless of which brick triggered the spawn.
The reason this is subtle: she removed the variables thinking "the brick already knows where it is, so the PowerUp will too." Sprites don't share positions automatically. The brick has to tell the PowerUp where to go, and the PowerUp has to move there before cloning.
Fix: restore both halves of the handshake. The brick records its position into drop-x and drop-y, the PowerUp goes to those coordinates, then clones:
when I receive (brick-hit v)
change [score v] by (10)
if <(pick random (1) to (5)) = (1)> then
set [drop-x v] to (x position)
set [drop-y v] to (y position)
broadcast (spawn-power-up v)
end
delete this clone
when I receive (spawn-power-up v)
go to x: (drop-x) y: (drop-y)
create clone of (myself v)
The rule: when one sprite needs to spawn another at its location, you need a small "shared whiteboard" of position variables. Sprite A writes to it, Sprite B reads from it, then clones. This handshake is everywhere in clone-heavy games — projectiles, particles, drops.
Recap 3 min
You used a Scratch list as a menu of choices — three power-up names sitting in the power-ups list, picked at random via item (random index) of [power-ups v]. A 1-in-5 random check on each brick decides whether a power-up drops; the list pick decides which. Each falling PowerUp clone owns its own power-up-type (a For-this-sprite-only variable), so multiple clones can fall at once without overwriting each other. When the paddle catches a clone, an apply-power-up broadcast tells the paddle which branch to run.
- List as menu
- Using a list to hold the set of valid choices a script might pick from. Different from using a list as a sequence of records — same Scratch block, different intent.
- length of [list v]
- A reporter in the Variables palette that returns how many items are currently in the list. Combine with pick random to grab a random index that's always in range, even if the list grows.
- For this sprite only
- A variable scope where every clone gets its own private copy. Used here so each falling PowerUp clone remembers its type independently of every other clone.
- Random gate
- A if wrapped around pick random () = 1 that makes an event happen only some of the time. The denominator is the rarity knob — bigger denominator means rarer event.
- Position handshake
- The pattern where one sprite writes coordinates to shared variables and another reads them before cloning. The reason power-ups can spawn at the brick that died, instead of wherever the PowerUp sprite happened to be sitting.
Homework 2 min
The Loot Table Drill. Open your power-up project and add two new power-ups of your own design. They can be helpful or hurtful — designer's choice.
- Pick two ideas. Examples:
slow-ball(the ball moves at half speed for 8 seconds),multi-ball(spawn two extra ball clones),shrink-paddle(paddle goes to 60% for 8 seconds — a bad power-up the player wants to dodge),laser(the paddle can shoot upward for 5 seconds). - Add a costume to the PowerUp sprite for each, named exactly to match (e.g.
slow-ball). - Add each name to the
power-upslist. - Add a new branch to the paddle's when I receive (apply-power-up v) handler for each new type.
- Play 5 rounds and observe. Are the new power-ups too frequent? Too rare? Boring?
Save as HW-L4-34-My-Power-Ups.sb3.
Bring back next class:
- The
.sb3file. - Your answer to: "Which of your two new power-ups is more fun, and why? If you had to delete one, which would it be?"
Heads up for next class: SCR-L04-35 adds the second half of game-feel polish — particle effects when bricks explode, and screen shake on big hits. Subtle, fast, and the difference between "blocks vanish" and "blocks explode". Bring your power-up project; we'll add particles directly to it.