Learning Goals 3 min
By the end of this lesson you will be able to:
- Explain what a hat block is and why every script needs one on top.
- Drag
when flag clickedfrom Events and snap an action underneath it. - Build two separate scripts under two hats and show that one click starts both.
Warm-Up 7 min
New arc, new project. Start a fresh Scratch project and choose the Spotlight backdrop — this is where the dance show will live. You have used the yellow flag block since Lesson 1 without ever asking what it actually is. Today you find out, because the show needs a dependable start cue before it can have anything else.
Quick-fire puzzle
Wei Jie dragged a single Motion block into the Script Area, with no hat above it, and clicked the green flag. What happened?
move (50) steps
Reveal the answer
Nothing at all. The block sat there while the flag did nothing, because Scratch had no idea when it was supposed to run. A script with no hat is a recipe with no “start cooking when…” line.
One quirk worth knowing: double-click a lone block and Scratch runs it once on the spot. But the green flag will never touch it — only blocks under a flag hat hear the flag.
New Concept — hat blocks and events 15 min
Think of a hat block as a starting whistle. A troop stands in a field ready to march, and nothing happens until the leader blows. The whistle is the green flag; the hat block is the one listening for it.
The block we are studying today
| Block | Category | What it does |
|---|---|---|
when flag clicked | Events | Waits, doing nothing, until the green flag is clicked — then runs everything snapped underneath, top to bottom. |
The shape is the rule
Every block’s shape tells you where it is allowed to go. A hat block has a rounded top, which means nothing can ever sit above it. That is not a suggestion — try it and the block will refuse to snap.
Events, in plain words
An event is just something that happens at a moment in time. The flag being clicked is one. A key being pressed is another. A sprite being clicked is a third. The hat block’s job is to say which event this script is waiting for.
Right now you know one hat. Lessons 16 and 17 add two more, and that is when your dance show starts to feel interactive.
Many hats, many scripts
A project can hold as many hat blocks as you like, and each one starts its own separate stack. Two flag hats means two scripts, both waking on the same click and running side by side at the same moment.
This is worth trying, because it is genuinely surprising the first time: a sprite really can speak and move simultaneously if the two jobs live under two different hats.
Why it matters
Every project you will ever build begins with at least one hat. Without one, blocks are bricks in a box. With one, they become something that answers back.
Worked Example — the cat opens the show 15 min
We build a two-block script, then split it into two scripts to see the difference for ourselves.
Step 1 — Find the Events category
Click the yellow dot in the Blocks Panel. The panel fills with yellow blocks, and the very first is the one you want.
Step 2 — Drag the hat in on its own
Drop when flag clicked anywhere in the Script Area. Click the green flag. Nothing happens — and that is worth pausing on. The hat is listening perfectly well; there is simply nothing below it to do.
when flag clicked
Step 3 — Give it something to do
Click the purple Looks dot and drag say [Hello!] for (2) seconds under the hat until it snaps.
when flag clicked
say [Hello!] for (2) seconds
Step 4 — Click the flag
A bubble appears beside the cat, holds for two seconds, and vanishes. Click again and it repeats exactly.
Step 5 — Make it yours
Click the words inside the say block and type Selamat pagi!. Run it again — your cat now opens the show in Malay.
Step 6 — Add a second hat
Now the interesting part. Drag in a second when flag clicked, well away from the first, and snap move (100) steps underneath it.
when flag clicked
say [Selamat pagi!] for (2) seconds
when flag clicked
move (100) steps
Step 7 — One click, two scripts
Click the flag. The cat speaks and moves at the same instant, because both hats heard the same event and ran independently.
Compare that with putting both blocks under one hat: then the cat would speak first and move afterwards. Same two actions, completely different result, decided entirely by how many hats you used.
What changed: you have used this block for fourteen lessons. Now you know what it is, why it must sit on top, and what happens when you use more than one.
The full assembled stack (your reference)
when flag clicked
say [Selamat pagi!] for (2) seconds
Try It Yourself — three small builds 12 min
Goal: Change the opening line. Swap the message for a greeting of your own and run it again.
when flag clicked
say [Apa khabar?] for (2) seconds
Think: the hat has no opinion about what sits below it. Change the action as often as you like — the cue never changes.
Goal: Make the cat announce itself, then walk on stage. One hat, two actions, in the order that tells the better story.
when flag clicked
say [Here I go!] for (2) seconds
move (50) steps
Think: under one hat, blocks run strictly top to bottom. Swap the two and the cat walks on in silence, then speaks. Neither is wrong — but they tell different stories.
Mini-mission: at the same time, or one after the other? Build the same two actions twice — once so they happen together, once so they happen in sequence — and be ready to explain what makes the difference.
It works if: you can show both versions running, and say in one sentence what decides whether actions overlap or queue up. Keep each stack under 8 blocks.
Think: nothing about the say block or the move block changed between your two versions. So what did?
Mini-Challenge — hello from both sides 5 min
“Aisyah’s cat works the room”
On one flag click, the cat should greet the audience from one side of the stage, cross to the other side, and greet them again from there.
It works if:
- One flag click runs the whole thing.
- The cat starts at one side and finishes at the other.
- Each greeting appears while the cat is actually at that side, not on the way.
- You used the flag hat exactly once.
Reveal one valid solution (teacher)
Set the cat’s x to -200 in Sprite Properties first, then build:
when flag clicked
say [Hello from the left!] for (2) seconds
glide (2) secs to x: (200) y: (0)
say [Hello from the right!] for (2) seconds
Four blocks, about six seconds. Pupils who use two hats will see both greetings fire at once at opposite ends — a useful failure that proves they understood the previous section a little too well.
Recap 2 min
The yellow block you have used since Lesson 1 has a name: a hat block. Its rounded top means nothing can sit above it, so it always starts a script. It waits for one particular event — here, the green flag — then runs everything below it. And a project can hold as many hats as you like, each starting its own script, all waking on the same click.
- Hat block
- A block with a rounded top. Sits at the top of a script and listens for one event.
- Event
- Something that happens at a moment in time — a flag click, a key press, a sprite click.
- when flag clicked
- The Events hat that waits for the green flag, then runs the blocks below it.
- Script
- A stack of blocks headed by one hat. Each script runs independently of the others.
Homework 1 min
Three greetings, one click. Build one script with a single hat and three greetings in a row, so the cat welcomes the audience properly.
- Drag in
when flag clicked. - Snap three
say [Hello!] for (2) secondsblocks below it. - Change the three messages to Selamat pagi!, Apa khabar? and Jumpa lagi!
- Click the flag and watch all three appear in turn. Screenshot your Script Area.
when flag clicked
say [Selamat pagi!] for (2) seconds
say [Apa khabar?] for (2) seconds
say [Jumpa lagi!] for (2) seconds
Bring back next class:
- A screenshot of your four-block script.
- Your answer to: “What would happen if you gave each greeting its own hat block instead? Would you still be able to read all three?”
Heads up for next class: SCR-L01-16 brings a brand-new hat — when [space v] key pressed. Your cat starts answering the keyboard.