Learning Goals 3 min
By the end of this lesson you will be able to:
- Create a fall-speed variable, set its starting value, and tick the box that shows it on the Stage so the player watches it climb.
- Use the () mod () operator with if <> then to fire a milestone every few catches.
- Replace a hard-coded change y by (-5) in the kuih clone with change y by ((0) - (fall-speed)) so kuih fall faster the moment fall-speed changes.
Warm-Up — the game that never gets harder 7 min
You finished L02-39 with a Catch the Kuih game that works — kuih fall, score climbs, lives drain. Aisyah's little brother played it after class. He scored 42 on his first try.
Open last lesson's clone-mover. It looks something like this:
when I start as a clone
go to x: (pick random (-220) to (220)) y: (170)
show
repeat until <(y position) < (-170)>
change y by (-5)
if <touching (Basket v) ?> then
change [score v] by (1)
go to x: (pick random (-220) to (220)) y: (170)
end
end
change [lives v] by (-1)
delete this clone
Click the flag and play for thirty seconds. Then for two minutes. Then for five.
Reveal — what's wrong
Nothing changes. Minute one is exactly as hard as minute five. The game has no arc. Once you've figured out how fast to slide the basket, you can play forever without losing. Real arcade games — Pac-Man, Tetris, Flappy Bird — get faster as you score. That keeps you leaning in. Today we add the arc.
The trick is one little variable, fall-speed, that changes itself whenever the player hits a milestone.
New Concept — a variable that grows with the score 15 min
Until now, the 5 inside change y by (-5) has been a hard-coded number — typed straight in, never changing. Today we replace it with a variable, then slowly raise that variable while the game plays.
Step one — a new variable
Open the orange Variables palette. Click Make a Variable. Name it fall-speed. Make it For all sprites — the kuih clones need to read it. Tick its checkbox so it shows on the Stage as a watcher. Watching the number tick from 5 to 6 to 7 is half the fun.
when flag clicked
set [fall-speed v] to (5)
Step two — use the variable in the fall
Inside the kuih clone, swap the hard-coded -5 for the variable. Scratch has no "negative variable" block, so we subtract the variable from zero:
when I start as a clone
go to x: (pick random (-220) to (220)) y: (170)
show
repeat until <(y position) < (-170)>
change y by ((0) - (fall-speed))
if <touching (Basket v) ?> then
change [score v] by (1)
go to x: (pick random (-220) to (220)) y: (170)
end
end
change [lives v] by (-1)
delete this clone
Click the flag. The game plays exactly as before — kuih drop at 5 pixels a frame. Good. We haven't broken anything; we've just made the speed changeable.
Step three — the milestone trigger
Now the part that makes the variable climb. Every five catches, fall-speed goes up by one. The block that asks "is the score a multiple of five?" uses the mod operator from the green Operators palette:
if <((score) mod (5)) = (0)> then
change [fall-speed v] by (1)
end
What is mod? It's the leftover after division. 17 mod 5 is 2 (5 goes into 17 three times with 2 left). 20 mod 5 is 0 (no leftover). So (score) mod (5) = 0 is true exactly when the score is a multiple of 5 — every 5th catch.
Worked Example — adding speed-up to last lesson's game 12 min
Open your SCR-L02-39 Catch the Kuih project. We upgrade it in eight steps. Save a copy first if you are nervous — call it L02-40-Speedy.sb3.
Step 1 — Make the fall-speed variable
Variables palette → Make a Variable → name fall-speed → For all sprites → OK. Tick the checkbox so the watcher shows on the Stage.
Step 2 — Initialise it at the flag
On the Stage (or the basket — either is fine, pick one), add:
when flag clicked
set [fall-speed v] to (5)
set [score v] to (0)
set [lives v] to (3)
Step 3 — Switch the kuih to use the variable
Click the kuih sprite. Find the clone's repeat-until. Replace change y by (-5) with change y by ((0) - (fall-speed)). Use the green () - () block, with a literal 0 on the left and the fall-speed reporter on the right.
Step 4 — Test that nothing's broken
Click the flag. Play 10 seconds. Kuih should fall at exactly the old speed — because fall-speed sits at 5, the same as the old hard-coded number. If kuih fall up, you put fall-speed on the wrong side of the minus.
Step 5 — Find where score changes
Click the basket sprite. Find the catch script. It probably has a touching-the-kuih check that bumps the score:
when flag clicked
forever
if <touching [Kuih v] ?> then
change [score v] by (1)
end
end
Step 6 — Add the milestone check
Right after change [score v] by (1), drop in a new if-then that uses mod:
when flag clicked
forever
if <touching [Kuih v] ?> then
change [score v] by (1)
if <((score) mod (5)) = (0)> then
change [fall-speed v] by (1)
end
end
end
Step 7 — Play and watch the watcher
Click the flag. Watch the fall-speed widget. At 5 catches it jumps to 6 and kuih drop quicker. At 10: 7. At 15: 8. By 30 catches the kuih are fast.
Step 8 — Add a tiny celebration
Optional but lovely. Inside the milestone if-then, before the speed bump, add a quick sound so the player gets feedback they unlocked a new level:
if <((score) mod (5)) = (0)> then
play sound [Magic Spell v] until done
change [fall-speed v] by (1)
end
The full assembled stack — on the basket
when flag clicked
forever
if <touching [Kuih v] ?> then
change [score v] by (1)
if <((score) mod (5)) = (0)> then
play sound [Magic Spell v] until done
change [fall-speed v] by (1)
end
end
end
What you just built: the difficulty curve. Every arcade game you've loved has one. You now know how to add one to any of yours: one variable, one mod-based milestone, one change.
Try It Yourself — three difficulty-scaling drills 15 min
Goal: Change the milestone from "every 5 catches" to "every 3 catches". The game ramps up faster. Make exactly one change.
if <((score) mod (3)) = (0)> then
change [fall-speed v] by (1)
end
Think: Mod is your dial. mod 3 means "every third catch". mod 10 means "every tenth — gentler arc". Same code, totally different feel.
Goal: Cap the speed. Right now fall-speed grows forever and the game becomes impossible. Add an if-then so it stops climbing after 12.
if <((score) mod (5)) = (0)> then
if <(fall-speed) < (12)> then
change [fall-speed v] by (1)
end
end
Think: Even the toughest arcade game has a max difficulty. Capping the variable makes a game punishing but fair.
Goal: Add a second knob — spawn-wait. The kuih spawner waits a fixed time between drops; make the wait shrink as the score grows. Start at 1.5, drop a kuih every spawn-wait seconds, shrink by 0.1 every 5 catches (floor 0.3).
when flag clicked
set [spawn-wait v] to (1.5)
forever
create clone of [myself v]
wait (spawn-wait) seconds
end
if <((score) mod (5)) = (0)> then
change [fall-speed v] by (1)
if <(spawn-wait) > (0.3)> then
change [spawn-wait v] by (-0.1)
end
end
Think: Real designers tune three or four knobs at once — speed, spawn rate, enemy count, score multiplier. Same pattern, repeated. You've built a tunable game, not just a faster one.
Mini-Challenge — the speed-up that fires too often 5 min
"Priya's runaway kuih"
Priya copies the lesson code and tests. After two catches, her fall-speed watcher reads 87. The kuih are a vertical blur. She shows you this script on the basket:
when flag clicked
forever
if <touching [Kuih v] ?> then
change [score v] by (1)
end
if <((score) mod (5)) = (0)> then
change [fall-speed v] by (1)
end
end
The score is 5 (or 0, or 10…). What does the milestone check do? How often?
Reveal one valid solution
The milestone check is outside the catch if-then. So it fires every frame of the forever loop, not just when the score changes. The moment the score is 5, the milestone is true — and stays true while the score is 5. The forever runs ~30 times a second, so fall-speed gets bumped ~30 times a second until the score finally ticks to 6.
Also: at the very start, score is 0. And 0 mod 5 = 0 is true! So Priya's fall-speed is bumped ~30 times per second from frame one, before she catches anything.
The fix is to nest the milestone check inside the catch if-then, so it runs at the moment a catch happens — exactly once per catch:
when flag clicked
forever
if <touching [Kuih v] ?> then
change [score v] by (1)
if <((score) mod (5)) = (0)> then
change [fall-speed v] by (1)
end
end
end
Same blocks. Different nesting. The fence between "always check" and "only check when something happens" is the whole game. Where you put the if-then matters more than what's inside it.
Recap 3 min
You added a difficulty curve. A new variable, fall-speed, replaces a hard-coded number in the kuih's fall script — now changing the variable changes how fast they drop. A milestone check using () mod () fires every Nth catch and bumps the variable. The watcher on the Stage shows the climbing number. The same pattern — one variable, one milestone, one bump — scales to spawn rate, enemy count, every difficulty knob in arcade games.
- Difficulty scaling
- Making a game get harder as the player gets better. The arc that keeps arcade games addictive.
- Hard-coded
- A number typed straight into a block (like
-5in change y by (-5)) that can't change while the game runs. The opposite of a variable. - Mod (modulo)
- The leftover after division. () mod () in Operators.
(score) mod (5) = 0is true exactly when the score is a multiple of 5 — the classic "every N" trigger. - Watcher
- The little box on the Stage showing a variable's value. Tick the checkbox by the variable name to turn it on.
- Milestone
- A score (or time, or count) at which something special happens. Today's milestone: "every 5 catches → speed up".
Homework 2 min
The Tuner. Build a tuned version where the difficulty arc feels just right — not too easy, not impossible.
- Open today's L02-40 project. Save as
HW-L2-40-Tuner.sb3. - Change the milestone from
mod 5tomod 3,mod 7, andmod 10in turn. Play each a minute. Pick the best. - Cap
fall-speedat 10 (see the Medium task). Make sure the watcher actually stops climbing. - Add a starting speed of your choice — 3 for "chill mode", 8 for "panic mode". Reset to it at the flag.
- Show say [LEVEL UP!] for (1) seconds on the basket every milestone, before the speed bump. Make sure it doesn't fire 30 times a second (re-read the mini-challenge).
Save your final tuned version. Play three minutes straight. Note your highest score.
Bring back next class:
- Your
HW-L2-40-Tuner.sb3. - Your highest score, the milestone you chose (
mod 3,mod 5…), and one sentence on why it felt best. - Your answer to: "What's one other variable in this game that could get harder as the score grows, besides fall-speed?"
Heads up for next class: SCR-L02-41 · Catch the Kuih is the arc finale Build lesson. You'll polish the whole game into a portfolio piece — kuih sprites, a basket you control, a Score+Lives HUD, the speed-up, a game over and a title — then save and share it.