Learning Goals 3 min
By the end of this lesson you will be able to:
- Use the Make a Block dialogue to invent a new pink block — name it, click OK, and find the matching define hat that appears in the Script Area.
- Snap a stack of existing blocks under the define hat to give your new block its behaviour — the "recipe" behind the recipe card.
- Drag your invented block out of the My Blocks palette and use it as if it were any other block — and understand that editing the define stack changes every caller at once.
Warm-Up — predict the pink hat 7 min
Last lesson we talked about Aisyah's cat that meows three times in three different scripts. Today she's going to bundle the routine. Before she clicks anything, predict what will happen.
Aisyah opens My Blocks, clicks Make a Block, types meow three times in the name field, and clicks OK. What appears in her Script Area?
Reveal the answer
A brand new pink hat-block appears, all on its own in the workspace:
define meow three times
It's an empty recipe card. There's a name on the front (meow three times), but the back is blank. Scratch is waiting for Aisyah to snap blocks underneath the hat — those blocks become the recipe.
At the same time, in the pink My Blocks palette, a new callable block appears: a single pink block that says meow three times. Aisyah can drag it into any script right now — but until she fills in the define stack, dragging it does nothing visible. The card is there; the recipe is blank.
Today you'll make your own meowing cat. By the end of the lesson, three different scripts on the same sprite will each contain a single meow three times block — and when you decide to change the timing, you'll only edit one place.
New Concept — define stack and caller block 15 min
Every My Block you create has two halves. They look totally different, and the difference matters.
Half 1 — the define stack
The define stack is the recipe. It's a pink hat — define meow three times — with regular blocks snapped under it. It lives in the Script Area, alongside your other scripts. The define stack runs whenever the matching pink caller block is used — never on its own. The hat has no flag, no key-press trigger. It's not started by an event. It's started by being called.
define meow three times
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
Half 2 — the caller block
The caller block is the pulled-out recipe card. It's a single pink block named meow three times sitting in the My Blocks palette. You drag it into any script you like. Each time it runs, Scratch quietly jumps over to the define stack, runs every block under the hat, then jumps back to where you called from. You barely notice the jump — to you, it just looks like meow three times happened.
when flag clicked
meow three times
say [Done!] for (1) seconds
The crucial idea — one recipe, many callers
You can drag the meow three times caller out of the palette as many times as you want. Once in your flag-clicked script. Once in your space-pressed script. Once inside an if-then for touching the edge. Every single one runs the same recipe — the same six blocks under the same define hat.
And here's the magic: change the wait from 0.5 to 0.3 in the define stack, and all three callers instantly get the new timing. You didn't edit the three scripts. You edited the recipe card once. Everyone using the card gets the new version.
How to make one — the three clicks
- Click My Blocks at the bottom of the sidebar.
- Click the big Make a Block button.
- Type a name (e.g.
meow three times) into the field on the pop-up. Click OK.
That's it. The pink define-hat appears in the Script Area. The matching caller appears in the My Blocks palette. You're ready to fill in the recipe.
What a good name looks like
The name on a My Block is its face. Make it readable. Use lowercase, use real English (or Malay, your choice), say what the block does, not how. Examples:
- Good:
meow three times,reset to start,flash red,shake the screen. - Bad:
do thing,block1,script,asdf.
Worked Example — make your first My Block 15 min
Open a new Scratch project. Keep the default cat. Add the Meow sound if it's not already loaded (Sound tab → choose a sound → Meow).
meow three times My Block and call it from two different hat scripts — same recipe, two uses.Step 1 — Open the pink palette
Look at the sidebar. At the very bottom, below Variables, there's a pink rectangle labelled My Blocks. Click it. The palette is empty except for one big button.
Step 2 — Click Make a Block
Click the big Make a Block button. A pop-up appears in the centre of the screen with a text field labelled "block name" and a few options below (for inputs — ignore those today).
Step 3 — Name your block
Click into the text field. Type meow three times — all lowercase, with spaces. Don't press Enter yet; that submits the form.
Step 4 — Click OK
Click the blue OK button at the bottom of the pop-up. Two things happen at once:
- A pink hat-block appears in your Script Area: define meow three times. It's alone and empty.
- In the My Blocks palette, a new pink caller block has appeared: meow three times. Hover it — it lights up like any other block.
Step 5 — Fill in the recipe
Click the define-hat to make sure you're working on the right stack. Then snap the following under it: play sound [Meow v], wait (0.5) seconds, play sound [Meow v], wait (0.5) seconds, play sound [Meow v]. Five blocks of recipe under one pink hat.
define meow three times
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
Step 6 — Build the first caller script
In an empty area of the Script Area, drop a fresh hat: when ⚑ clicked. Now go to the My Blocks palette and drag your pink meow three times block out — snap it under the flag-clicked hat.
when flag clicked
meow three times
Step 7 — Click the flag
Press the green flag. The cat meows. Waits. Meows. Waits. Meows. Your invented block works. You wrote one set of blocks in one place and ran them with a single new block. That's the whole idea of Cluster C.
Step 8 — Add a second caller
In a free spot of the Script Area, drop another hat: when [space v] key pressed. Drag a second copy of the meow three times caller from the palette and snap it under. Now you have two scripts, both two-block — flag triggers a meow-routine, space triggers the same meow-routine.
when [space v] key pressed
meow three times
Step 9 — Edit the recipe in one place
Go back to the define stack. Change every wait (0.5) seconds to wait (0.2) seconds. Now click the flag — the cat meows fast. Press space — the cat meows fast. You edited one place; both callers obey. If you'd built each script the long way, you'd have to edit four wait-blocks in two different scripts and hope you didn't miss any.
Step 10 — Look at how short the script area is
Scroll your Script Area. Count the visible blocks across all three stacks: 6 (define) + 2 (flag caller) + 2 (space caller) = 10 blocks. Without the My Block, you'd have 1 + 5 + 1 + 5 = 12 blocks, in two scripts that looked identical from the middle down — and any change would mean editing both. You've already saved yourself a tiny bit, and you've made the project much easier to read.
What you just built: the same skill that real programmers use every single day. Find a chunk that repeats, name it, bundle it. Your scripts shrink, your bugs concentrate in one spot, and your code reads like English. This is the most important habit in Cluster C.
Try It Yourself — three My Blocks to make 12 min
Goal: Make a My Block called jump up on the cat. The recipe is: change y by (50), wait (0.2) seconds, change y by (-50). Then call it from two scripts — one on the flag, one on the space key.
define jump up
change y by (50)
wait (0.2) seconds
change y by (-50)
Think: Now try changing the recipe to a bigger jump — say change y by (100). Both your scripts get the bigger jump automatically. You just gave yourself a "jump strength" you can tune in one place.
Goal: Make a My Block called reset to start that does the boring setup work for a sprite at the beginning of a game. Recipe: go to a start position, set size, switch to first costume, show, point right. Then call it from the flag-clicked script.
define reset to start
go to x: (-200) y: (0)
set size to (100) %
switch costume to [costume1 v]
show
point in direction (90)
Think: "Reset to start" is the My Block you will write in almost every Scratch game you ever build. Many games also have a "you lost a life — reset" moment. The same reset to start block can run there too. Write once, call from anywhere.
Goal: Make two My Blocks on the cat — flash red and shake hard. Recipes are up to you. Then write one game-feel script: when the cat touches the edge, flash red and shake hard. The script should be three blocks long.
when flag clicked
forever
if <touching [edge v] ?> then
flash red
shake hard
end
end
Think: Notice how the if-then now reads like English: "if touching edge then flash red, shake hard". A teammate could open your project and instantly understand the game feel without scrolling through 20 blocks of motion and looks. That readability is the second-biggest reason to use My Blocks.
Mini-Challenge — Hafiz's silent cat 5 min
"The cat that won't meow"
Hafiz creates a My Block called meow three times. He drags the caller into a flag-clicked script. He hits the flag. The cat is dead silent. Here are his two stacks:
define meow three times
when flag clicked
meow three times
say [Meowed three times!] for (1) seconds
What's gone wrong, and how does Hafiz fix it?
Reveal one valid solution
Hafiz made the block but never wrote the recipe. The define stack is just an empty hat. When his caller runs, Scratch dutifully jumps over to the define stack, finds nothing under the hat, jumps back, and continues. So the cat does "run the meow three times block" — there's just nothing inside it to do.
The fix is to snap the five sound and wait blocks under the define-hat:
define meow three times
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
Now the caller actually has something to run. Lesson: making a My Block creates an empty recipe card — you still have to write the recipe on the back. A pink caller block in a script is a promise; the define stack is the proof.
Recap 3 min
You made your first My Block. Three clicks — My Blocks palette → Make a Block → name it → OK — and a pink define meow three times hat appears in the Script Area while a matching pink caller appears in the palette. Fill the recipe by snapping blocks under the define hat. Use the caller anywhere — every call runs the same recipe. Change the recipe in one place; every caller obeys instantly. You just learnt one of the most important habits in all of programming.
- Define stack
- The pink hat define your-block-name plus all the blocks snapped under it. This is the recipe. It lives in the Script Area but never runs on its own — only when called.
- Caller block
- The pink block in the My Blocks palette named after your invented block. Drop it in any script; it stands in for everything under the matching define hat.
- Call
- The act of using a caller block in a script. When the script reaches a pink caller, Scratch quietly runs the whole define stack, then comes back. Real programmers say "call a function" for the same thing.
- One source of truth
- The principle that there should be exactly one place where each piece of behaviour is defined. A My Block makes its define stack the one source of truth for that behaviour — edit it once, every caller changes.
- Per-sprite scope
- A My Block lives on the sprite where you made it. The dog can't see the cat's
meow three times. If you need the same routine on multiple sprites, you either remake it on each sprite or use a broadcast (L02-20).
Homework 2 min
The Reskin Drill. Open one of your favourite Level 2 projects — Whack-a-Tikus, Catch the Kuih, Simple Pong, your choice. Pick one routine that appears in at least two scripts (a reset, a sound effect, a costume cycle, anything). Turn it into a My Block. Then:
- Make a My Block with a clear English name for the routine.
- Move the original blocks under the define-hat (or just copy them and delete the originals).
- Replace every occurrence of that routine in your scripts with the pink caller block.
- Click the flag and confirm the project still behaves the same way.
- Now change the recipe in one tiny way — make the wait shorter, the sound louder, the costume different — and confirm both callers got the change.
Save as HW-L3-15-FirstMyBlock.sb3. The project doesn't have to be impressive — the goal is to feel the moment when one change in one place ripples through your whole project.
Bring back next class:
- The
.sb3file. - Your answer to: "In your project, how many blocks did the Script Area lose when you replaced the routine with the My Block? Count before and after."
Heads up for next class: SCR-L03-16 teaches My Blocks with inputs. Right now your meow three times always meows three times — boring. Next lesson you'll learn how to make a meow (n) times block that takes a number, so you can say "meow 5 times" or "meow 10 times" from the same recipe. That's where My Blocks get really powerful.