draw star (size) draws colourful stars of any size, anywhere on the Stage. Every lesson adds one skill — today we understand why My Blocks exist, so the Machine's plan is set.Learning Goals 3 min
By the end of this lesson you will be able to:
- Explain in your own words why programmers bundle blocks together — and why typing the same 5 blocks three times is a smell, not a feature.
- Identify the pink My Blocks palette in the Scratch sidebar and the Make a Block button at the top of it.
- Describe the analogy: a My Block is like a recipe card — write it once, follow it many times. (Real programmers call this a function.)
Warm-Up — the copy-paste cat 7 min
Aisyah is building a project where the cat meows three times whenever something interesting happens — when the flag is clicked, when a key is pressed, and when the cat touches the edge. Here's her script so far:
when flag clicked
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
Now look at her other two scripts — same sprite:
when [space v] key pressed
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
when flag clicked
forever
if <touching [edge v] ?> then
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
wait (0.5) seconds
play sound [Meow v]
end
end
Question: Aisyah decides she wants the meows to be 0.3 seconds apart instead of 0.5. How many blocks does she have to change?
Reveal the answer
Six. Two wait blocks in each of three scripts. And if she misses even one — say she forgets the third script — the cat will meow at two different speeds depending on what triggered it. The bug will be hard to spot because every script looks right on its own.
This is what programmers call a copy-paste smell. The moment you see the same group of blocks in three different places, your brain should itch. There must be a better way.
Today's lesson is the better way. It has a name: My Blocks. By the end of Cluster C, Aisyah will have a single block named meow three times — and she'll change the timing once, in one place, and all three scripts will obey.
New Concept — bundling blocks with My Blocks 15 min
You've used six palettes so far — Motion, Looks, Sound, Events, Control, Sensing, Operators, and Variables. There's one more at the very bottom of the sidebar that you've probably ignored: My Blocks. It's pink. It's empty. Until you put something in it.
What is a My Block?
A My Block is a block you invent. You take a stack of blocks that you find yourself writing over and over, bundle them up, give the bundle a name — and from then on, dragging your new block out of the My Blocks palette is the same as dragging out the whole stack. One pink block stands in for many blocks.
For Aisyah's cat, she'd invent a block called meow three times. The bundle behind it is the five-block routine. Then every one of her three scripts becomes:
when flag clicked
meow three times
The recipe-card analogy
Think of a real recipe card for roti canai. The card says: flour, water, oil, knead, rest, flatten, fry. Seven steps. When Mak wants to make roti for breakfast, she doesn't write the seven steps on a sticky note again — she pulls out the recipe card. When she wants roti for tea, she pulls out the same card. The card is written once. It's used many times.
A My Block is exactly the same idea. The definition (the seven steps) lives in one place. The call (pulling out the card) can happen anywhere. If Mak changes the recipe — say she adds salt — she edits the card once, and every future breakfast and tea gets the new version automatically.
Where to find it
Open Scratch. Look at the sidebar of palettes on the left. Below Variables — at the very bottom — there's a pink button labelled My Blocks. Click it. The palette is empty except for one big rectangular button: Make a Block. That's the door into Cluster C.
when flag clicked
my custom block
The real-programming name
In every other programming language — Python, JavaScript, C++, the lot — a bundled-up reusable named chunk of code is called a function. Scratch calls them My Blocks because the team wanted a friendly name. But you should know the proper word too: when you go on to write real code in a few years, you'll write functions all day. My Blocks are the kid-friendly door into one of the most important ideas in all of programming.
Three reasons to use a My Block
- Don't Repeat Yourself. Real programmers shorten this to DRY. If you write the same five blocks three times, your project has fifteen blocks doing what five could. Change one and you have to change all three.
- Names tell stories. A stack of move (10), turn ↻ (30), move (10), turn ↻ (30) says nothing. Bundle it into a My Block called
draw half-starand the script suddenly reads like English. Anyone — including future-you — can understand it at a glance. - One brain at a time. When you're debugging a long script, you can only hold so much in your head. If the script says
meow three times, you don't have to think about how it meows — just that it does. You can focus on the bug elsewhere.
Worked Example — spotting where a My Block would help 10 min
No Scratch needed today — open your Cluster B capstone from last lesson (the shopping helper) and a notebook. We'll walk through reading code with My-Block eyes.
Step 1 — Look at the helper's read-back loop
Find these three blocks in your helper:
set [i v] to (1)
repeat (length of [shopping v])
say (item (i) of [shopping v]) for (1) seconds
change [i v] by (1)
end
end).Step 2 — Imagine a second list
Say your helper now has a shopping list and a chores list. To read back chores, you'd write the same five-block pattern again, just changing shopping to chores. That's a copy-paste smell.
Step 3 — Imagine the My Block that fixes it
You'd want a single block called read out my list. The bundle behind it is the loop-through-list pattern. Drop the pink block once for shopping, once for chores. Two pink blocks instead of ten regular blocks. (In L03-16 you'll learn how to make the My Block take an input so it can read different lists. For now, just feel how much shorter the script would get.)
Step 4 — Open one of your old projects
Pick any project from Level 2 — maybe Whack-a-Tikus (L02-43) or Catch the Kuih (L02-41). Scroll through the scripts on a single sprite. Find any group of 3 or more blocks that appears in more than one script. Circle them in a notebook. Give that bundle a name.
Step 5 — Hold onto the list
Bring the list to class next lesson. We'll pick one of your bundles together and turn it into a real My Block in L03-15. The exercise of spotting places where a My Block would help is half the skill — the actual block-making is the easy half.
Step 6 — Spot the trap
Don't bundle blocks that look similar but actually do different things. Two scripts that both start with go to x: () y: () aren't doing "the same thing" — they're probably going to different coordinates. The blocks have to be identical, or one block has to be the same with a small variation (which is what inputs in L03-16 are for).
Step 7 — Spot the win
Three scripts on the same sprite that all begin with the same six blocks for "reset to start position, set size to 100%, switch to first costume, show, point in direction 90, set rotation style". That's a screaming candidate for a My Block called reset to start. You will write that block in your career as a Scratcher many, many times.
The big idea, one more time
Today we didn't make a single My Block. We just learnt to see places they belong. A programmer who can spot duplication is more valuable than a programmer who types fast. Next lesson, you'll learn the three clicks to actually create one.
Try It Yourself — three spotting drills 12 min
Goal: Open Scratch, click My Blocks in the sidebar (the pink one at the bottom), then click Make a Block. A pop-up appears. Read every label and option on the pop-up out loud to yourself. Then click Cancel. Don't make a block — just see the door.
Think: What do the four bits — the name field, the "Add an input" buttons, "Add a label", and "Run without screen refresh" — look like they might be for? Guess wildly. You'll find out for real over the next four lessons.
Goal: In your notebook, list three real-life examples of something that's like a My Block — something that's "written once, used many times". Examples to get you started: a recipe card, a song you've memorised, the way you sign your name.
when flag clicked
sign my name
say [Done!] for (1) seconds
Think: The point of My Blocks isn't only saving typing. It's that the name on the block is a tiny piece of documentation. Anyone reading sign my name instantly knows what's about to happen.
Goal: Open your three favourite Level 2 projects. For each one, find the longest stack of blocks under any single hat. Count the blocks. Now ask: are there any chunks within that long stack that you could give a clear English name to? Write the name and the chunk size in your notebook.
For example, if you find a 22-block stack that has a clear "reset everything" chunk of 7 blocks at the top, your notebook entry would be:
when flag clicked
reset everything
go to x: (-200) y: (0)
Think: A good name for a My Block is a sentence. set everything up is good. do stuff is bad. reset score and lives, hide all sprites, switch to level 1 is too long — that's a sign the block is doing three jobs and should be three smaller blocks.
Mini-Challenge — name that bundle 5 min
"Daniel's draw-a-shape script"
Daniel shows you this script on a sprite with the pen extension. He wants to know which chunks would be good My Blocks and what to name them.
when flag clicked
go to x: (0) y: (0)
clear
pen down
set pen color to [#ff0000]
set pen size to (4)
move (100) steps
turn cw (90) degrees
move (100) steps
turn cw (90) degrees
move (100) steps
turn cw (90) degrees
move (100) steps
turn cw (90) degrees
pen up
go to x: (150) y: (0)
pen down
set pen color to [#00aa00]
set pen size to (4)
move (60) steps
turn cw (60) degrees
move (60) steps
turn cw (60) degrees
move (60) steps
turn cw (60) degrees
Reveal one valid solution
Two strong My Block candidates jump out. First, the four move 100, turn 90 pairs are clearly "draw a square" — that's a My Block. Name it draw square. Second, the pen down + set pen colour + set pen size triple appears twice with different colours — for today, you'd name it something like start drawing, knowing that in L03-16 you'll learn how to make the colour an input.
What the script could look like with My Blocks:
when flag clicked
go to x: (0) y: (0)
clear
start drawing
draw square
pen up
go to x: (150) y: (0)
start drawing
draw triangle
From 23 blocks down to 9 visible blocks. The script reads like English. And if Daniel wants to change his square from 100 steps to 80, he edits the My Block definition once — both future squares change. That's the whole sales pitch for My Blocks in one example.
Recap 3 min
You met the idea of My Blocks — the pink palette at the bottom of Scratch's sidebar where you invent your own blocks. The point isn't only saving typing; it's that a well-named My Block makes a long script readable, lets you change behaviour in one place instead of many, and is your first taste of functions — the most important idea in real programming. You didn't make a block today. You learnt to see where blocks would help. Next lesson, the three-click recipe to create one.
- My Block
- A block you invent yourself by bundling other blocks together and giving the bundle a name. Lives in the pink My Blocks palette at the bottom of the sidebar.
- Function
- The real-programming name for a My Block. In Python you'd write
def meow_three_times():and the indented code under it is the bundle. Same idea — different friendly skin. - DRY (Don't Repeat Yourself)
- A core rule of programming: if you see the same code in two places, you're probably one bug-fix away from forgetting one of them. Bundle it.
- Make a Block
- The big rectangular button at the top of the empty My Blocks palette. Clicking it opens the dialogue where you name your new block. You'll click it for real in L03-15.
- Copy-paste smell
- The feeling a programmer gets when they catch themselves copying a stack of blocks. That itch is your brain telling you to make a My Block instead.
Homework 2 min
The Spotting Notebook. Open three projects you've already built — anything from Level 1 or Level 2 — and for each one:
- Look at the scripts on the main sprite. Find one chunk of 3+ blocks that either repeats inside the same script or appears identically in two different scripts.
- Write the chunk down (you can sketch the block shapes, or just list the block names).
- Invent a clear English name for what that chunk does.
do thingdoesn't count.shrink and fade outis great.
You'll have at least three spotted chunks and three names. Bring the notebook to next class.
Bring back next class:
- The notebook with your three spotted chunks + their names.
- Your answer to: "Why is naming so important? Imagine you opened someone else's Scratch project. Would
meow three timesormy custom blockbe more useful as a name? Why?"
Heads up for next class: SCR-L03-15 is the hands-on twin of today's lesson. You'll click Make a Block, type a name, watch a pink define meow three times hat appear in the Script Area, and snap the meow stack under it. Three clicks to your first invented block.