Learning Goals 3 min
By the end of this lesson you will be able to:
- Pair a when this sprite clicked hat with a change [score v] by (1) body block.
- Click on a sprite five times and predict the watcher's new value before each click.
- Reset the score back to
0on green-flag start using set [score v] to (0).
Warm-Up 7 min
In Arc 2/4 you learnt set, change, show, and hide. Today you wire one of them to a hat block you have seen but never used with a variable: when this sprite clicked.
Quick-fire puzzle
Mei Ling builds two separate scripts on the cat sprite. The score variable starts at 0. She clicks the green flag, then clicks the cat three times. What does the watcher read?
when flag clicked
set [score v] to (0)
when this sprite clicked
change [score v] by (1)
Reveal the answer
The watcher reads 3. Here's the timeline: flag clicked → score reset to 0. Click the cat once → score becomes 1. Click again → 2. Click again → 3.
Two hat blocks. Two scripts. Same sprite. Same variable. Each script runs independently when its own hat fires.
New Concept — clicks become score 15 min
A real catch game has a kuih falling from the sky. The player has to click (or touch) it before it lands. Every catch gives one point. We don't have the "falling from the sky" trick yet — that's a Level 2 lesson. But we already have everything we need for the scoring half: a click that counts.
Think of a fairground game where you press a button to earn a point. The button is the sprite. Pressing it is the click. The score is the prize counter. We are building exactly that, minus the cuddly toys.
| Block | Category | What it does |
|---|---|---|
| when this sprite clicked | Events (yellow) | Hat block. Fires its script every time the user clicks (or taps) this particular sprite — not the Stage, not another sprite, only this one. |
| change [score v] by (1) | Variables (orange) | The +1 increment you met yesterday. The watcher counts up live. |
| when ⚑ clicked | Events (yellow) | Old friend. Used here to reset the score back to 0 when the player presses the green flag. |
| set [score v] to (0) | Variables (orange) | The reset block. Runs once, at flag-click, to wipe the score before a new round. |
Two hats, two scripts, one sprite
This is the trick: the cat (or kuih, or any sprite) has two separate scripts. Each starts with its own hat block. They never collide, because each hat listens for a different event:
- The when ⚑ clicked script fires the moment the player clicks the green flag — it resets things.
- The when this sprite clicked script fires every time the player clicks the sprite itself — it counts.
Both scripts touch the same score variable, but at different moments. The variable is shared between them — the box doesn't belong to one script. It belongs to the project.
The full picture on the Stage
Why it matters
This is the simplest possible game loop: an event, a counter, a visible result. Every catch-the-X, whack-a-Y, click-the-Z game is built on this same skeleton. In Level 2, you'll add a moving target. In Level 3, you'll add lives. For today, the skeleton is enough — and it already feels like a real game.
Worked Example — clickable kuih scoreboard 15 min
Open Scratch. If the cat is still in your project, rename it to kuih via the Sprite Properties panel (the same way you did in SCR-L01-02). You should still have the score variable from yesterday — its watcher should sit in the top-left of the Stage.
Step 1 — Reset script
Drag when ⚑ clicked into an empty patch of the Script Area. Below it, snap set [score v] to (0). That's the whole reset script — two blocks.
when flag clicked
set [score v] to (0)
Step 2 — Make space for the second script
Click in an empty area of the Script Area, well below your first stack. We'll build a separate stack here. Two scripts on one sprite — same Script Area, different hats.
Step 3 — Drag the click hat
From the yellow Events category, find when this sprite clicked. It looks just like the green-flag hat, but with a hand-pointer icon instead of a flag. Drag it into the Script Area, separate from your reset script.
Step 4 — Snap the change block under it
From the orange Variables category, drag change [score v] by ( ) beneath the click hat. Type 1 in the round socket. Drop-down should say score.
when this sprite clicked
change [score v] by (1)
Step 5 — Test the reset
Click the green flag. The watcher in the top-left of the Stage flicks back to 0 (or stays at 0 if it was already there). The cat doesn't move. Nothing else happens. Good — that's exactly what the reset script does.
Step 6 — Test the score
Now click on the kuih sprite directly. The watcher jumps to 1. Click again — 2. Click again — 3. Click five times — 5. The score climbs one per click.
Step 7 — Mix the two
Click the kuih a few more times to get the score up to 8. Now click the green flag. Watcher snaps back to 0. Click the kuih again — 1. The reset is doing its job perfectly.
That is a complete (very simple) catch-game scoring loop. Two scripts. One sprite. One variable. One click = one point.
What changed: yesterday you could change the score with a set or change block inside a single flag-clicked script. Today the score reacts to the user — every click on the sprite is a real event the player can feel.
Both scripts together
when flag clicked
set [score v] to (0)
when this sprite clicked
change [score v] by (1)
Try It Yourself — three small builds 12 min
Goal: Big points per click. Change the 1 in your score-up script to 10. Click the kuih five times. Predict the final score, then check.
when this sprite clicked
change [score v] by (10)
Think: 5 clicks × 10 points each = 50. The watcher reads 50. Big-point clicks make a great rare bonus item.
Goal: Add a "thanks" message. Make the kuih say Sedap! ("Tasty!" in Malay) every time it's clicked, then add to the score. Keep the reset script as-is.
when this sprite clicked
say [Sedap!] for (1) seconds
change [score v] by (1)
Think: The cat says Sedap! for one second before the score climbs. Try swapping the order — does the score now jump before the message? (Hint: yes. Order matters.)
Goal: Lose points by clicking the flag. Sometimes a game punishes you for restarting too early. Modify the reset script so clicking the flag subtracts 5 from the score instead of zeroing it. (Hint: change by (-5).)
when flag clicked
change [score v] by (-5)
Think: Now the green flag doesn't reset — it costs 5 points each press. After three flag presses, the score is -15. Watchers happily display negative numbers. (This isn't how a real game should work — it's just to show that any two scripts can share the same variable.)
Mini-Challenge — race to 10 5 min
"Click the kuih until the score hits 10 — and the cat celebrates"
Extend your project so that, on the green flag, the score resets to 0 and the kuih grows back to size 100 just in case. Then each click on the kuih adds 1 to the score and says the current score aloud. Aim to click the kuih ten times — your final reading should be 10, and the cat's last spoken number should match.
It works if:
- The green flag resets the score watcher to
0. - Every click on the kuih bumps the watcher by exactly
1. - The kuih says the new score after each click (e.g. on click 7, it says "7").
- Total blocks used across both scripts is ≤ 8.
Reveal one valid solution
Two stacks. The reset stack is 3 blocks; the click stack is 3 blocks. 6 blocks total, well under the cap of 8.
when flag clicked
set [score v] to (0)
set size to (100) %
when this sprite clicked
change [score v] by (1)
say (score) for (1) seconds
Click the flag → score back to 0, kuih back to full size. Then click the kuih ten times, watching the cat shout each new number out loud. On the tenth click, the kuih says "10". That's a tiny but real catch-game scoreboard.
Looking ahead: in Level 2 we'll make the kuih actually fall from the sky and detect when the cat touches it — no more clicks needed. Then it really is a catch game.
Recap 2 min
Today you wired the click hat when this sprite clicked to the change [score v] by (1) block, and added a green-flag reset that snaps the score back to 0 at the start of each round. Two scripts. One sprite. One shared variable. That is the bones of every catch game — and the first project where Scratch reacts to the player.
- when this sprite clicked
- An Events hat block that fires every time the user clicks (or taps) this particular sprite. Different from when ⚑ clicked, which fires on the green flag.
- increment
- Coding word for "add one". change [score v] by (1) increments the score.
- reset
- To put a variable back to its starting value before a new round. Almost always done in the when ⚑ clicked script using set [score v] to (0).
- game loop
- The repeating pattern of "player does something → score (or game state) changes → screen shows the new state". Your kuih project is the tiniest possible game loop.
Homework 1 min
The Pasar Pagi clicker. Choose any sprite from the Scratch library — a fruit, a drink, a toy. Rename it to something Malaysian (roti canai, teh tarik, kuih, satay). Build the same two-script scoreboard from today's worked example. Click the sprite ten times. Reset. Repeat.
- Choose a sprite and rename it.
- Build the reset script (2 blocks) and the click-to-score script (2 blocks).
- Test it — click the sprite, watch the score climb.
- Screenshot the Script Area (both stacks visible).
- Screenshot the Stage right after your tenth click, with the watcher reading
10.
Bring back next class:
- Both screenshots.
- Your written answer: "What would happen if you forgot the green-flag reset script entirely?" (Hint: think about what the score reads at the start of round 2.)
Heads up for next class: SCR-L01-43 is a full Build lesson — Catch the Roti Canai — where everything from L01-40, L01-41, and L01-42 gets put to work in one bigger project. You'll combine motion, looks, sound, and the score variable into your first real game.