π§© Lesson 4.2: My Blocks β Make Your Own Blocks
What if Scratch doesn't have the block you want? Make it yourself! In this lesson you'll bundle a chunk of code into a brand-new block with its own name, like jump or reset game. Programmers have a name for this, and it's one of the most useful ideas in coding.
π What You'll Learn
By the end of this lesson, you will be able to:
- Explain why naming a chunk of code makes projects easier to read and reuse
- Create a custom block with the My Blocks category and the Make a Block dialog
- Attach steps to the define hat block and use your new block anywhere in that sprite
- Add an input so one block can behave differently each time
- Coach your child to spot repeated code and turn it into their own block
Estimated Time: 35 minutes β’ Project: a jump block, a dance (times) block, and a reset game block
In This Lesson
π Learn It: Why make your own blocks?
As projects grow, the same few blocks keep showing up: a jump here, the same jump there, another copy for when the cat touches something. Long, repetitive scripts are hard to read, and changing the jump means hunting down every copy.
Think of a recipe card that says "Make pancakes." Those two words stand for a whole list of steps: crack the eggs, whisk, pour, flip. Once the card is written, you just say "make pancakes."
A custom block works the same way. You write the steps once, give them a name, and from then on one block stands for all of them. Programmers call a named chunk of code a function. Your child doesn't need the word, but you're doing exactly what professional coders do every day.
Three scripts say "jump," but the jumping steps live in one place. Change them there, and every jump changes.
π Learn It: The Make a Block dialog
Click the pink My Blocks circle at the bottom of the block categories, then the Make a Block button. A dialog opens with a pink block that says block name.
-
Name your block
Type a short action word that says what it does, like jump.
-
Add an input (optional)
Add an input (number or text) puts a slot in your block so you can hand it a value each time, like how many times to dance. You name the slot, for example times. (The boolean input is for yes/no values; skip it for now.)
-
Add a label (optional)
Add a label adds plain words between inputs so the block reads like a sentence, for example dance (times) times.
-
Decide on "Run without screen refresh"
Normally Scratch redraws the stage each time through a loop, so you watch things move. Tick this box and the whole block runs in one go, showing only the end result. Handy for setup, but animations happen instantly (you never see the jump!). Leave it unticked.
Click OK. Two things appear: your new block in the My Blocks palette, and a pink define hat block in the code area.
π Learn It: The define block
The define block is your recipe card: whatever you snap underneath it is what your new block does. On its own it never runs; it waits until another script uses the block.
π The recipe (define)
The steps go under here.
π£οΈ Using it (the call)
Drag it from My Blocks like any other block.
Using the block is called calling it: the green flag script calls jump, Scratch runs the define script's steps, then comes back and carries on.
π οΈ Try It: Mini-project 1 β a jump block
Start a new project with the cat. Make a block named jump (no inputs, screen refresh unticked) and build this under the define hat:
Up ten little steps, down ten little steps. Now give the player a way to use it:
Press space and the cat hops. Now add a when this sprite clicked β jump script too: two ways to jump, one set of steps. Want a higher jump? Change the define script once, and both scripts get it.
π οΈ Try It: Mini-project 2 β add an input
An input lets one block do slightly different things. Click Make a Block, type dance, click Add an input (number or text) and name it times, then Add a label and type times. Click OK.
The new define block contains a round pink times oval: the input's value. Drag it out of the define block (you get a copy) into the repeat slot:
Your palette block now has a white slot for any number:
On the recipe card, the input is "how many pancakes?" Same steps, different number.
π‘ Challenge: make jump (height)
Right-click the define block β Edit and add a number input called height. Use the Operators block (height / 10) as the "change y by" amount going up, and (0 β (height / 10)) going down. Now jump (50) is a hop and jump (150) a leap.
π οΈ Try It: A reset game block
Some of the most useful blocks simply tidy up. Every game puts things back to the start when the green flag is pressed, and that setup list gets long. Wrap it in a block called reset game:
(Make the score and lives variables first, as in Lesson 3.2.) Now the green flag script reads like plain English.
β You'll use this in the capstone
In Lessons 4.3β4.4, starting with Capstone Part 1 β Plan It & Build the Core, you and your child build Star Catcher: a bowl catching falling star clones from Lesson 4.1. The bowl's reset game block is exactly this one.
π‘ My Blocks belong to one sprite
A custom block only appears in the palette of the sprite you made it in. To reuse it, drag the define script onto the other sprite's picture in the sprite list; it copies over.
π Common problems & fixes
| What you see | Likely cause | Fix |
|---|---|---|
| Using the block does nothing | The steps are sitting loose, not attached to the define hat | Drag them until they snap under the define hat |
| The input is always blank or 0 | The oval came from somewhere else, or was never placed | Drag the input oval out of the define block itself into the slot |
| My block isn't in the palette | A different sprite is selected | Select the sprite you made it in, or drag the define script onto the other sprite |
| The jump or dance happens instantly | "Run without screen refresh" is ticked | Right-click the define block β Edit β untick it |
π± Growth mindset: going back isn't going backward
Cleaning up code that already works can feel like admitting the first version was "wrong." It isn't. Programmers call it refactoring and do it constantly, because every project teaches a better way. When your child spots a repeated chunk in an old game, say: "Look how much you've grown β you can see things now you couldn't last month." Then say the same about your own projects.
π¬ Teach It: New words for the computer
For kids, the big idea isn't "functions." It's that they invent new words and the computer learns them.
Start with a game of "new word"
Before touching the computer, play it out loud:
"I'm going to teach you a new word: zoomba. Zoomba means clap twice and spin around. Ready? Zoomba! β¦Now let's teach the computer a new word."
Let them find the repeats
When the same blocks appear twice, don't point it out. Ask:
"I see those same blocks twice. What would you call what they do? What if that were one block with that name?"
The name is theirs ("boing" is perfect; silly names stick), and so is the number: let them try dance 1, dance 20, dance 100.
π§ Ages 5β7
"Teaching the computer a new word." Build the define script together; they pick the name and use the block. Skip inputs.
π§ Ages 8β11
They can build jump and dance alone. Introduce inputs with dance (times), then challenge them to invent a block like sneeze or celebrate.
π§ Ages 12+
Have them refactor their Lesson 3.2 game, replacing setup and repeated chunks with named blocks, then explain why it's easier to change.
β οΈ Common kid bug
They type "times" into a slot instead of dragging the oval out, so Scratch sees the word, not the number. Point at the pink oval: "The value lives in here β drag it out."
π― Quick Check
Question 1: Where do you put the steps that your new block should do?
Question 2: Your jump block works, but the cat seems to teleport instead of hopping. What's the likely cause?
Question 3: You made a reset game block on the Bowl sprite, but it's missing when you click the Star sprite. Why?
π Learning Journal
Take five minutes to write it down
A notebook or notes app works. Writing things down helps them stick, and lets you look back and see how far you've come.
- Key concepts: In your own words, what's the difference between the define block and using it? What does an input add?
- What clicked: The recipe card, two scripts sharing one jump, or dance 3 becoming dance 6?
- Questions & confusion: Is dragging the input oval still fuzzy? Screen refresh? Note exactly where you got stuck.
- Ideas to try: Name one block you wish Scratch had. Could you build it now?
- Progress & feelings: How does it feel to make blocks instead of just using them? What did your child name their first one?
π‘ Teach It tip: Have your child start a "dictionary" page: each block they invent, with its name and a drawing of what it does.
Summary & What's Next
π Key Takeaways
- A custom block (a function) names a chunk of code so you write it once.
- Make a Block sets the name, inputs, and labels; leave Run without screen refresh unticked.
- Steps go under the define hat; drag the input oval out of it to use its value.
- My Blocks belong to one sprite; drag the define script to share it.
π What You've Accomplished
- Made your first custom block and used it from two scripts
- Built a block with an input that changes its behavior
- Wrote a reset game block ready for the capstone
π Before the Next Lesson
- Save your project with the reset game block
- Keep your falling-star clones project from Lesson 4.1 handy
- Ask your child for one idea to add to a catching game
β Common Questions at This Stage
Is this too advanced for my 6-year-old?
Not the idea: young kids get "teaching the computer a new word" right away. Skip inputs, build the define script together, and let them enjoy using the block they named.
When should we make a custom block instead of just copying blocks?
If you've copied the same group of blocks twice, or a script no longer fits on screen, give that chunk a name. There's no penalty for doing it later.
I renamed my block and now things look different. Did I break something?
Probably not. When you edit a block, Scratch updates every place it's used automatically, which copied blocks can't do.
π Looking Ahead
Next is the big one: the two-part capstone (Lessons 4.3β4.4), starting with Lesson 4.3: Capstone Part 1 β Plan It & Build the Core. You'll combine arrow-key controls, falling star clones, score and lives, and your reset game block into Star Catcher, planning it on paper with your child first.
π Encouragement for the Journey
You're no longer just using Scratch's tools β you're making your own. That's a real shift, and your child gets to watch you make it.