draw star (30), draw star (60), and draw star (90) produces three different stars from the same recipe.Learning Goals 3 min
By the end of this lesson you will be able to:
- Open the Make a Block dialog and click "Add an input — number or text" to give your My Block a slot.
- Read the define meow (n) times hat and explain what the round (n) reporter does inside the define stack.
- Call the same My Block with two different numbers — meow (5) times and meow (10) times — and predict what each does.
Warm-Up — Aisha's hardcoded meow 7 min
Last lesson Aisha built her first My Block, meow three times. The define stack looked like this:
define meow three times
repeat (3)
play sound (Meow v) until done
end
Today her teacher asks for a five-meow cat, and tomorrow he'll want a ten-meow cat. Aisha groans — does she really need to make meow five times and meow ten times as separate blocks?
Reveal the answer
No — and that's the whole point of this lesson. A My Block can have an input slot: a round hole the caller fills with any number. One block, infinite different counts. Aisha will rebuild meow three times as meow (n) times and then call it with whatever number she likes.
By the end of the lesson, copy-pasting My Blocks just to change one number will feel as silly as copy-pasting the cat sprite just to give it a different name.
New Concept — adding an input 15 min
The label of a My Block (the words like "meow" and "times") is for humans. The inputs are for the computer. So far your My Blocks have had labels only. Today they grow inputs.
The Make a Block dialog, button by button
Open the My Blocks palette and click Make a Block. The pink dialog opens with one text box and three little circles underneath. Those circles are the add input buttons:
- Add an input — number or text. A round slot. Holds numbers or strings. This is the one we use today.
- Add an input — boolean. A hexagonal slot. Holds true/false reporters. (Next term.)
- Add a label. A second word in the block name, so you can write nice readable names like "meow (n) times" instead of "meow (n)".
Building meow (n) times
Type the word meow into the name box. Click Add an input — number or text. A round slot appears beside the word, with a placeholder name like number or text. Click that placeholder and rename it to n. Click Add a label and type times. Press OK.
Two things happen in your script area:
- A pink meow (n) times caller appears in the My Blocks palette, with a round hole between "meow" and "times".
- A define hat drops into the script area: define meow (n) times. The (n) on the hat is a round reporter — you can drag copies of it into any number slot inside the define stack.
define meow (n) times
repeat (n)
play sound (Meow v) until done
end
Calling the block
Back in your normal script area, drag the pink meow (n) times caller out of the palette and snap a number into its hole. Same block, two different calls:
when flag clicked
meow (5) times
wait (1) seconds
meow (10) times
The mental model — the (n) is a delivery
Think of the caller as a parcel: it carries the number into the define stack. The hat unwraps the parcel and gives the number a name — n. From that point on, every (n) inside the define is a copy of whatever the caller delivered. Call with 5, every (n) is 5. Call with 10, every (n) is 10.
Worked Example — Aisha's meow (n) times 12 min
Let's rebuild Aisha's My Block together. Eight steps, one tiny dialog, big payoff.
meow (n) times My Block and call it with 5 and 10 — same define, different inputs.Step 1 — Open Aisha's project
Start with the default cat. Make sure the Meow sound is in the Sounds tab (it's there by default).
Step 2 — Make a Block
Click the pink My Blocks category, then Make a Block. The dialog opens.
Step 3 — Name the first word
Type meow in the text box.
Step 4 — Add the number input
Click Add an input — number or text. A round slot appears. Click the placeholder and rename it to n.
Step 5 — Add the second label
Click Add a label and type times. The block now reads meow (n) times. Click OK.
Step 6 — Fill the define stack
The define meow (n) times hat is in your script area. From Control: repeat (10). Snap it under the hat. From Sound: play sound (Meow v) until done. Drop it inside the repeat.
Step 7 — Swap the 10 for (n)
This is the magic step. Drag the round (n) reporter off the define hat itself and drop it onto the 10 in the repeat block. The 10 disappears and the (n) snaps in.
Step 8 — Call it from a hat
From Events: when ⚑ clicked. Snap two pink callers underneath. Type 5 in the first and 10 in the second. Add a wait (1) seconds between them.
The full assembled stacks
define meow (n) times
repeat (n)
play sound (Meow v) until done
end
when flag clicked
meow (5) times
wait (1) seconds
meow (10) times
Click the flag. Five meows, a beat of silence, ten meows. What you just built: a reusable function with a parameter — the foundation of every programming language ever. In Python it's def meow(n):. In JavaScript it's function meow(n). In Scratch it's that pink define hat.
Try It Yourself — three input drills 15 min
Goal: Build a My Block called jump (height) that makes the cat change y by +height, wait 0.2 seconds, then change y by -height. Call it twice from the flag — once with 50, once with 100.
define jump (height)
change y by (height)
wait (0.2) seconds
change y by ((0) - (height))
Think: The same My Block now powers small hops and big leaps. Imagine adding jump (random) later for a chaotic cat.
Goal: Build say (message) loudly — a My Block that takes a text input. Inside the define, use say () for (1) seconds with the (message) reporter dropped in, and set [pitch v] effect to (50) before saying it. Call it with Selamat pagi! and Apa khabar?.
define say (message) loudly
set [pitch v] effect to (50)
say (message) for (1) seconds
Think: Inputs aren't only for numbers. Greetings, names, scores, sound names — any value the caller wants to deliver.
Goal: Build a two-input block: walk (steps) and turn (angle). Inside: move (steps) steps then turn ↻ (angle) degrees. Use it inside a repeat (4) with 100 and 90 to draw an invisible square. Then change to 100 and 120 — what shape?
define walk (steps) and turn (angle)
move (steps) steps
turn cw (angle) degrees
Think: With 100, 120 the cat traces a triangle (three 120° turns = 360°). One block, every regular polygon. L03-19 turns this into a full star drawer.
Mini-Challenge — Faiz's broken counter 5 min
"Why does it always meow seven times?"
Faiz proudly shows his meow (n) times block. He calls it with 5, but the cat meows 7. He calls it with 10, the cat meows 7. He calls it with 1, the cat meows 7. His define hat looks like this:
define meow (n) times
repeat (7)
play sound (Meow v) until done
end
What did Faiz forget?
Reveal the fix
The 7 inside repeat (7) is a hardcoded number — Faiz must have typed it earlier and never replaced it. The (n) from the hat is sitting there unused. The caller delivers a number, the hat receives it, and then the define stack ignores it and uses 7 anyway.
The fix is to drag the round (n) reporter off the define hat and drop it onto the 7. The 7 vanishes, the (n) snaps in:
define meow (n) times
repeat (n)
play sound (Meow v) until done
end
Lesson learned: an input slot is useless until you actually drag the reporter into a real slot in the define. The slot in the hat is the entrance. The reporter is the package. You still have to put the package on the shelf.
Recap 3 min
You upgraded My Blocks from fixed-behaviour helpers to configurable ones. By clicking Add an input — number or text in the Make a Block dialog, you give your block a round slot. The matching round reporter on the define hat carries the caller's value into the define stack — drag it into any number slot you like. One meow (n) times replaces an infinite family of fixed-count meow blocks. Inputs are the difference between a one-trick block and a real tool.
- Input (parameter)
- A slot on a My Block that the caller fills in with a value. Today's input is "number or text" — a round slot for numbers or strings.
- Round reporter (on the define hat)
- The little oval block sitting on the define hat with the input's name on it (e.g. (n)). Drag copies of it into number slots inside the define stack.
- Caller
- The pink block in the My Blocks palette that runs your custom block. Each caller fills in its own value for each input.
- Define hat
- The pink hat-shaped block define … that holds the body of a My Block. The shape on the hat shows what inputs the block takes.
- Label
- Plain words inside a My Block name — like "meow" or "times" — that exist only to make the block readable. Labels carry no value.
Homework 2 min
The Two-Input Toolbox. Build a single Scratch project with three new My Blocks.
- say (message) (times) times — two inputs. Inside the define, repeat (times) with say (message) for (1) seconds inside.
- grow by (percent) — one number input. Inside: change size by (percent). Call it three times in a row from one hat.
- walk (steps) bounce — one number input. Inside: move (steps) steps, then an if <> then with touching [edge v]? that does turn ↻ (180) degrees.
Save as HW-L3-16-Inputs.sb3. From one when ⚑ clicked, call all three blocks at least twice with different numbers each time.
Bring back next class:
- The
.sb3file. - Your answer to: "For grow by (percent), what number makes the sprite shrink instead of grow? Try it and write down the smallest sensible value."
Heads up for next class: SCR-L03-17 meets the Run without screen refresh checkbox in the Make a Block dialog — the same dialog you used today, but with one tickbox that changes everything about how the define stack runs.