Learning Goals 3 min
By the end of this lesson you will be able to:
- Name 3 backdrops after times of day:
morning,noon,night. - Use the new hat block when backdrop switches to [night v] to react to scene changes.
- Click the green flag and watch the cat say a different line at each time of day.
Warm-Up 7 min
Last lesson (Arc 3/5) you chained two kampung scenes with say + wait + switch. Today the cat gets smarter — it notices which time of day it is and reacts all by itself, without any wait blocks in the reaction.
Quick-fire puzzle
Wei Jie has three backdrops named morning, noon, night. The Stage starts on morning. He runs these two scripts on the cat. What does the cat say after one flag click?
when flag clicked
switch backdrop to [night v]
when backdrop switches to [night v]
say [Goodnight!] for (2) seconds
Reveal the answer
The cat says "Goodnight!". Click the flag → the first script changes the backdrop to night → the new hat block fires automatically → the second script says "Goodnight!" The two scripts talk through the Stage.
New Concept — backdrop-driven events 15 min
So far, every script started with one of three hats: when flag clicked, when this sprite clicked, or when [space v] key pressed. Today you meet a fourth: a hat that fires every time the Stage's backdrop switches to a chosen one.
The new block
| Block | Category | What it does |
|---|---|---|
| when backdrop switches to [backdrop1 v] | Events | A hat that fires when the Stage changes to the named backdrop. Listens to the Stage, not the mouse. |
Naming backdrops well
Backdrop names default to backdrop1, backdrop2, etc. — boring and forgettable. Rename your backdrops to something meaningful: morning, noon, night. The Events hat dropdown will then read clearly: "when backdrop switches to night". To rename, click the backdrop in the Backdrops list, then edit the name field at the top of the paint editor.
How the event flows
Imagine the Stage has a doorbell. Every time someone switches the Stage to night, the doorbell rings — and every sprite with a when backdrop switches to [night v] hat hears it and runs its script. You can put a different reaction in each sprite, or even two reactions in the same sprite.
when backdrop switches to [night] hat fires.Why it matters
Up to now you wrote each scene's behaviour inside the script that changed the scene. That works for two scenes — but as projects grow, the script gets tangled. The new hat lets each scene's reaction live in its own little script, attached to the right sprite. One job, one script — a cleaner way to grow.
Worked Example — three times of day 15 min
Open Scratch. Today the cat reacts to the Stage on its own.
Step 1 — Three named backdrops
Click the Stage card. Open Backdrops. Add three from the library — or paint your own. Rename them in the paint editor: morning (a sunrise scene like "Beach Sunrise"), noon (a bright sky like "Blue Sky"), night (a dark scene like "Stars" or "Night City").
Step 2 — Drag the new hat block (×3)
Click the cat. Open the Code tab. Open the yellow Events category. Drag when backdrop switches to [backdrop1 v] into an empty spot in the Script Area. Drag a second copy below it (leave a blank gap). Drag a third one (another blank gap). You now have three separate hat blocks — three separate scripts.
Step 3 — Set each dropdown
On the first hat, open the dropdown and pick morning. On the second, pick noon. On the third, pick night.
Step 4 — Add a say block under each
Open the purple Looks category. Snap say [Hello!] for (2) seconds under each hat. Edit the messages: Selamat pagi! under morning, Time for lunch! under noon, Goodnight! under night.
Step 5 — Build a flag-click "tour" script
Add a fourth, separate script that walks the Stage through all three times of day. This is the script that triggers the reactions:
when flag clicked
switch backdrop to [morning v]
wait (3) seconds
switch backdrop to [noon v]
wait (3) seconds
switch backdrop to [night v]
Step 6 — Run it
Click the green flag and watch:
- Stage flips to morning → cat says "Selamat pagi!" for 2 seconds.
- 3-second wait.
- Stage flips to noon → cat says "Time for lunch!" for 2 seconds.
- 3-second wait.
- Stage flips to night → cat says "Goodnight!" for 2 seconds.
What changed: last lesson, all the lines lived in one tangled script. This lesson, each line lives in its own tiny script, hanging off its own hat block. The "driver" script just changes scenes — the cat handles the rest.
The full set of scripts (your reference)
when flag clicked
switch backdrop to [morning v]
wait (3) seconds
switch backdrop to [noon v]
wait (3) seconds
switch backdrop to [night v]
when backdrop switches to [morning v]
say [Selamat pagi!] for (2) seconds
when backdrop switches to [noon v]
say [Time for lunch!] for (2) seconds
when backdrop switches to [night v]
say [Goodnight!] for (2) seconds
Try It Yourself — three small builds 12 min
Goal: Make the cat change size at night. Add this script to the cat — a second reaction to the same night event.
when backdrop switches to [night v]
set size to (60) %
Think: Two hats can listen for the same event. Both fire. The cat will say "Goodnight!" AND shrink at night.
Goal: Costume change at noon. Add this third reaction script so the cat swaps costume the moment noon arrives.
when backdrop switches to [noon v]
next costume
say [Mid-day stretch!] for (2) seconds
Think: When the driver flips the Stage to noon, three things now happen: the noon say-script, this costume-script, and any other scripts you've added. They all run together.
Goal: A "reset" script. The driver currently leaves the Stage on night. Add an extra hat that resets the size back to 100 whenever the Stage returns to morning.
when backdrop switches to [morning v]
set size to (100) %
Think: Now you can click the flag again and the cat starts fresh — full size, ready for the day. Resets like this make replayable projects.
Mini-Challenge — A day in the life 5 min
"What does the cat do at each time of day?"
Use today's hat block and earlier blocks to give the cat a unique action at each of the three times of day. The driver script (the one that walks through morning → noon → night) is the same as the Worked Example.
It works if:
- You have at least one script using when backdrop switches to [morning v], one for
noon, one fornight. - Each reaction uses at least one block from two different categories (e.g. a Looks block + a Motion block).
- Clicking the green flag plays the whole day automatically.
Reveal one valid solution
when backdrop switches to [morning v]
go to x: (-180) y: (0)
say [Selamat pagi!] for (2) seconds
when backdrop switches to [noon v]
move (100) steps
say [Lunchtime!] for (2) seconds
when backdrop switches to [night v]
move (100) steps
say [Tidur sekarang...] for (2) seconds
Three scripts, each combining Motion + Looks. The cat starts at the left in the morning, walks right at noon, walks again at night. The Stage tells the cat where it is in the day.
Recap 2 min
Today you met the fourth kind of hat block — one that listens to the Stage. By naming backdrops morning, noon, and night, the script becomes readable: "when the backdrop switches to night, say goodnight". Each scene now has its own small reaction script instead of one long tangled one.
- when backdrop switches to (hat block)
- An Events hat that fires when the Stage changes to the named backdrop. Lets sprites react automatically.
- Driver script
- A script (often started by the green flag) whose job is to walk the project through a sequence of scenes.
- Reaction script
- A small script attached to an event hat. Its only job is to do one thing when the event happens.
Homework 1 min
Three meals a day. Build a project where the cat reacts to three meal-time backdrops.
- Add three backdrops. Rename them
sarapan(breakfast),lunch,dinner. Use library scenes or paint your own. - Write a driver script (flag-click) that walks through sarapan → lunch → dinner with wait (3) seconds between each.
- Write three reaction scripts using when backdrop switches to [… v]. The cat says one Malaysian food per scene (e.g. "Roti canai!", "Nasi lemak!", "Char kway teow!").
Bring back next class:
- A screenshot of all your scripts (driver + 3 reactions).
- Your written answer: "Why is it easier to have three small reaction scripts than one big script with lots of waits?"
Heads up for next class: SCR-L01-34 is a Project lesson — you'll build a full 2-scene Hari Raya story where a kitchen fades to evening using switch backdrop, wait, and a costume change.