Learning Goals 3 min
By the end of this lesson you will be able to:
- Drag a when this sprite clicked block from the Events category.
- Snap a small action stack under it — for example a turn and a say.
- Click the cat on the Stage and watch it perform a mini-animation in response.
Warm-Up 7 min
Last lesson the cat reacted to keyboard keys — that was Arc 2. Today it reacts to itself being clicked: the crowd clicks the dancing cat and it does a trick!
Quick-fire puzzle
Priya built this script on her cat sprite. She clicked the green flag — nothing happened. She pressed every key — still nothing. Then she clicked the cat directly on the Stage. Bingo! What does the cat do?
when this sprite clicked
say [Ouch!] for (1) seconds
turn cw (15) degrees
Reveal the answer
Each click on the cat makes it say "Ouch!" for one second, then turn 15 degrees clockwise. Five clicks later, the cat has tilted 75 degrees to the right. Ten clicks and it is leaning sideways. The script only fires when the sprite itself is clicked — clicking on empty Stage space does nothing.
New Concept — the sprite as a button 15 min
Think of every sprite as a small button waiting to be pressed. A bus-stop button only does something when that button is pressed — not when you press the next bus stop's button. when this sprite clicked is the same idea: this script only runs when this sprite is clicked, not any other sprite, and not the Stage.
The new block
| Block | Category | What it does |
|---|---|---|
| when this sprite clicked | Events (yellow) | Waits for a mouse-click on the sprite carrying this script. Then runs every block snapped underneath. |
"This sprite" means the sprite the script lives on
The word this is important. The hat is tied to whichever sprite's Script Area you put it in. Put the same block on the cat — it fires when the cat is clicked. Put it on a star sprite — it fires when the star is clicked. Each sprite has its own version of the script.
when this sprite clicked
say [Hi! You clicked me.] for (2) seconds
Three hat blocks compared
You now know three hat blocks. They all live in the Events category. They all start scripts. They differ in which event they listen for:
- when ⚑ clicked — listens for the green flag (one place: above the Stage).
- when [space v] key pressed — listens for a keyboard key (you pick which one).
- when this sprite clicked — listens for a mouse-click on the sprite.
Why it matters
Clickable sprites are how Scratch projects can feel like apps. A menu of three clickable buttons; a story where you click the character to hear them speak; a puzzle where you click items to collect them. Without when this sprite clicked your sprites are statues. With it, they become interactive.
Worked Example — click-the-cat mini-animation 15 min
Open Scratch. We will build a script so that clicking the cat triggers a tiny animation: the cat says hello, turns half a circle, and says it again.
Step 1 — Open the Events category
Click the yellow Events dot in the Blocks Panel.
Step 2 — Drag the sprite-click hat
Grab when this sprite clicked. Drop it in the Script Area. (It looks just like the other yellow hats, but read the text — it says "this sprite clicked", not "key pressed".)
when this sprite clicked
Step 3 — Add a say block
Open the purple Looks category. Drag say [Hello!] for (2) seconds under the hat. Change the message to You clicked me!.
Step 4 — Add a turn block
Open the blue Motion category. Drag turn ↻ (15) degrees under the say block. Change the number to 180 — that flips the cat to face the other way.
Step 5 — Add a second say block
Drag another say [Hello!] for (2) seconds under the turn. Change the message to Now I am upside down!.
when this sprite clicked
say [You clicked me!] for (2) seconds
turn cw (180) degrees
say [Now I am upside down!] for (2) seconds
Step 6 — Click the cat
Move the mouse onto the cat on the Stage. Click. The cat says You clicked me!, then turns upside down, then says Now I am upside down!. Total: about four seconds of animation, all from one click.
Step 7 — Click it again
Click the cat once more. The script runs from the top. The cat says the same lines and turns another 180 degrees — so it ends up right way up again. A third click flips it once more.
What changed: the cat is no longer waiting for the green flag or a key. It is waiting for the mouse to click on its body. The trigger is now on the sprite itself.
The full assembled stack (your reference)
when this sprite clicked
say [You clicked me!] for (2) seconds
turn cw (180) degrees
say [Now I am upside down!] for (2) seconds
Try It Yourself — three small builds 12 min
Goal: Make the cat say Meow! every time it is clicked.
when this sprite clicked
say [Meow!] for (1) seconds
Think: Click the cat five times in a row. The cat meows five times. The flag never even has to be clicked.
Goal: Make the cat grow slightly each time it is clicked. Pair the click-hat with a Motion turn — make it dance.
when this sprite clicked
turn cw (30) degrees
move (20) steps
say [Wheeee!] for (1) seconds
Think: Each click turns the cat 30 degrees, walks it 20 pixels in the new direction, then it cheers. Twelve clicks = a full 360° spiral around the Stage.
Goal: Add a flag script that resets the cat, and a click script that animates it. Two hats on one sprite — the player resets with the flag, then plays with clicks.
when flag clicked
go to x: (0) y: (0)
point in direction (90)
when this sprite clicked
turn cw (45) degrees
say [Hello from Kuala Lumpur!] for (2) seconds
Think: Two different events trigger two different scripts. The flag resets the cat to centre, facing right. Each click then tilts and greets.
Mini-Challenge — three-stop tour 5 min
"Click the cat to tour three Malaysian cities"
Build a single click-script that takes the cat on a tour: KL, Penang, Johor Bahru. Each click triggers the full tour.
It works if:
- One click on the cat plays the whole tour from start to finish.
- The cat names three cities, one after the other.
- You used when this sprite clicked as the only hat block.
- You combined today's block with at least one earlier block (say, glide, or move).
Reveal one valid solution
when this sprite clicked
say [Kuala Lumpur] for (2) seconds
glide (2) secs to x: (-100) y: (0)
say [Penang] for (2) seconds
glide (2) secs to x: (100) y: (0)
say [Johor Bahru] for (2) seconds
Six blocks. One hat. The cat announces and glides between three positions, naming a Malaysian city at each stop. About 10 seconds end-to-end. Click again — the whole tour replays.
Recap 2 min
Today you met the third hat block — when this sprite clicked. Sprites can now react to a mouse click on their own body, turning every sprite into a clickable button. You have three hat blocks under your belt: flag, key, sprite-click. Each listens for a different event, and they can all live together on the same sprite.
- when this sprite clicked (block)
- An Events hat block that listens for a mouse click on the sprite carrying the script.
- Click event
- The moment the mouse is pressed on a sprite's visible pixels. Scripts with a click-hat react to it.
- This sprite
- The sprite whose Script Area you are looking at. The "this" in the hat block always means the script's own sprite.
- Interactive
- Something that reacts to the player. Click-hats are one of the easiest ways to make a sprite interactive.
Homework 1 min
The clickable cat menu. Build three different scripts on the cat, each starting with one of the three hat blocks you now know.
- Open Scratch.
- Drag a when ⚑ clicked hat. Under it, snap go to x: (0) y: (0) so the flag resets the cat to centre.
- Drag a when [space v] key pressed hat. Under it, snap move (50) steps.
- Drag a when this sprite clicked hat. Under it, snap say [Hi from Aiman's Cat!] for (2) seconds.
- Test all three: click the flag (cat resets), press space (cat moves), click the cat (cat speaks).
Bring back next class:
- A screenshot of all three scripts in your Script Area.
- Your written answer: "Which of the three triggers would you use for the start of a game? Which for an item the player picks up? Which for jumping?"
Heads up for next class: SCR-L01-18 introduces an orange Control block — wait (1) seconds. You will learn how to slow scripts down so the eye can keep up.