Learning Goals 3 min
By the end of this lesson you will be able to:
- Add a Basket sprite at the bottom of the Stage and steer it left/right with when [right arrow v] key pressed + change x by ().
- Inside the kuih's clone script, ask touching (Basket v) ? every frame, change [score v] by (1) on a catch, then snap the kuih back to the top to fall again.
- Tell the difference between a caught kuih (touches the basket) and a missed kuih (falls past
y: -170).
Warm-Up — your shower from yesterday 7 min
Open your HW-L2-37-Kuih-Shower.sb3 from last lesson. Click the flag. Kuih rain from random x positions, every second, falling at 5 pixels per frame, deleting at the bottom. Good. (We reuse the score variable you first made in arc F's HUD.)
Here's the question: your finger is the only thing trying to catch the kuih right now. The Stage doesn't know about you. Predict — if we draw a basket at the bottom and a kuih falls onto it, what happens?
Reveal
Nothing. The kuih falls through the basket as if it isn't there. Scratch sprites have no built-in physics — they don't notice each other unless we ask touching (other sprite) ?. The basket is just a picture until we wire it up.
Today we add the wiring. Two ideas: a player-controlled basket at the bottom, and a touching-the-basket check inside the kuih's clone script.
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)
end
delete this clone
New Concept — touching another sprite 15 min
In L02-06 you used touching [edge v] ? — a hexagonal block asking the Stage "am I, this sprite, touching the edge?". The dropdown in that block also lists every other sprite in your project. Pick a sprite name and it asks "am I touching that one?".
The basket sprite
The basket is just a normal sprite — a bowl, a kuih tray, whatever fits. You paint or import it, drag it to roughly y: -150 (just above the bottom edge), and give it two tiny scripts so the arrow keys move it left and right.
when [right arrow v] key pressed
change x by (10)
when [left arrow v] key pressed
change x by (-10)
That is all the basket needs to be controllable. It knows nothing about kuih. The kuih do the asking — "am I touching it?".
Catch = score, then snap back to the top
When a kuih touches the basket, two things happen: the Score goes up by 1, and the kuih jumps back to the top to fall again. Snapping back means one clone can be caught over and over — a steady supply of kuih without spawning new clones for every catch.
- Caught. Kuih touches the basket mid-fall. We change [score v] by (1) and send it back to
y: 170with a fresh random x. - Missed. Kuih's
ydrops below-170without touching the basket. The loop ends and we delete this clone. (In L02-39 we will also change [lives v] by (-1) here.)
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
delete this clone
What "Basket" really is in that dropdown
The name in the dropdown — Basket — must match the basket sprite's name exactly. If you named it bowl, the dropdown offers bowl, not Basket. Scratch fills the dropdown from the sprites you have. Always check the exact name in the sprite pane.
Worked Example — adding the basket 12 min
Open your HW-L2-37-Kuih-Shower.sb3. We add the basket and wire the catch in eight steps.
Step 1 — Add the basket sprite
From the library, pick the Bowl sprite (or paint a basket). In the sprite pane, click its name and rename it exactly Basket (capital B). The exact name matters for the dropdown.
Step 2 — Park the basket at the bottom
Drag the Basket on the Stage to roughly x: 0, y: -150. We want it just above the bottom edge so kuih have time to be caught before they vanish.
Step 3 — Right arrow steers right
On the Basket, drag in when [right arrow v] key pressed. Snap on change x by (10).
Step 4 — Left arrow steers left
Drag in a separate when [left arrow v] key pressed. Snap on change x by (-10). Click the flag and hold the arrow keys — the basket slides along the bottom.
Step 5 — Switch back to the kuih sprite
Click the kuih in the sprite pane. We upgrade the clone script — the spawner stays exactly as it was.
Step 6 — Add the if-touching inside the loop
Find the repeat until. Inside it, below change y by (-5), snap on if <> then. From Sensing, drag touching ( v) ? and pick Basket in the dropdown. Drop it into the diamond.
Step 7 — Catch = score + snap back
Inside the if-then C, snap on change [score v] by (1) then go to x: (pick random (-220) to (220)) y: (170). The kuih scores a point and jumps back to the top.
Step 8 — Test
Click the flag. Kuih rain from above. Slide the basket with the arrow keys. Catch a kuih — the Score ticks up and the kuih leaps back to the top. Miss one and it vanishes at the bottom. The Stage stays clean.
The full assembled kuih script
when flag clicked
hide
forever
wait (1) seconds
create clone of [myself v]
end
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
delete this clone
What you just built: a game, not a slideshow. The player can fail (miss every kuih) or succeed (catch them). Tomorrow in L02-39 we count failures with lives and end the game when lives reach zero.
Try It Yourself — three game tweaks 15 min
Goal: Make the basket move faster. Currently each arrow press moves 10 pixels — try 20. Then try 5. Notice how it changes the feel.
when [right arrow v] key pressed
change x by (20)
when [left arrow v] key pressed
change x by (-20)
Think: Too fast and you overshoot the kuih. Too slow and you can't reach it. Tuning these numbers is game design, not just programming.
Goal: Play a "pop" sound on each catch. Use start sound [Pop v] from the Sound palette, right before the snap-back.
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
start sound [Pop v]
change [score v] by (1)
go to x: (pick random (-220) to (220)) y: (170)
end
end
delete this clone
Think: start sound kicks off the sound and moves on. play sound until done pauses the script. Use the right one for the job.
Goal: Stop the basket sliding off the edge. Right now holding the right arrow pushes the basket off-screen. Add an if-check so it refuses to go past x: 220 or below x: -220.
when [right arrow v] key pressed
if <(x position) < (220)> then
change x by (10)
end
when [left arrow v] key pressed
if <(x position) > (-220)> then
change x by (-10)
end
Think: This is a guard clause — a check that protects an action. Real games are full of them: "can I jump? am I on the ground?". You will see it again in L02-41 (the arc capstone).
Mini-Challenge — Priya's kuih-on-the-ground 5 min
"Priya's kuih pile up at the bottom"
Priya built the catch-and-reset. The basket works. But she notices missed kuih don't vanish — they stack invisibly at the bottom, and after a minute the spawner stops. Here is her kuih's clone script:
when I start as a clone
go to x: (pick random (-220) to (220)) y: (170)
show
forever
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
delete this clone
The script uses forever instead of repeat until. Catches are fine. But missed kuih…
Reveal the fix
A forever has no exit condition. Missed kuih keep "falling" past the bottom forever — invisible (Scratch clamps the display at the edge, but the script keeps running and y keeps dropping). They never reach the delete this clone at the bottom, because it lives after a forever that never ends.
After ~300 missed kuih, the clone cap kicks in and create clone of [myself v] silently does nothing. The game looks frozen.
The fix is to swap forever for repeat until <(y position) < (-170)>. Now there is a clean exit for misses:
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
delete this clone
The rule: a clone script must always reach a delete this clone. If it can't, you hit the 300-clone cap and the game silently breaks.
Recap 3 min
You wired up the first real interaction in Catch the Kuih. The basket listens to the arrow keys and slides along the bottom. Each kuih clone now asks touching (Basket v) ? every frame — and if true, the Score climbs and the kuih snaps back to the top to fall again. Missed kuih still delete when they fall past y: -170. The Stage stays clean and the game now has a score.
- Basket
- The player-controlled sprite at the bottom. In this lesson it has two scripts: one for the right arrow, one for the left.
- touching (sprite name) ?
- A hexagonal Sensing block that reports true when this sprite's costume overlaps the named sprite. The dropdown shows every other sprite in the project.
- Catch & reset
- On a catch: score a point, then send the kuih back to the spawn line so it falls again. One clone, many catches.
- Guard clause
- An if-check that wraps an action to make sure it is safe. The stretch task uses one to keep the basket on-screen.
Homework 2 min
Catch the Kuih v0.2. Take last night's kuih-shower project and add the basket exactly as in the worked example.
- Open
HW-L2-37-Kuih-Shower.sb3. Save a fresh copy asHW-L2-38-Catch.sb3. - Add the Basket sprite (rename it exactly
Basket). Build the two arrow-key scripts. - Add the if-touching to the kuih's clone script. Score +1 and snap back on a catch.
- Play for one minute. Catch every kuih, then catch none on purpose. Both should work cleanly — no pile-up, no frozen kuih.
- Tune the basket move speed and the kuih fall speed until the game feels fair-but-challenging for a 10-year-old. Write down the two numbers.
Save as HW-L2-38-Catch.sb3.
Bring back next class:
- The
.sb3file. - Your tuned numbers: "Basket moves ___ pixels per press. Kuih fall ___ pixels per frame."
- Your answer to: "What would change in the kuih clone script to make some kuih 'bad' that hurt you instead of help? Just describe in words."
Heads up for next class: SCR-L02-39 · Score & Game Over adds a lives variable that drops on every miss, and a broadcast (game over v) that ends the game when lives hit zero. Bring this project — we add to it directly.