- Learnt28 min · inputs, and reading them in the body
- Basic24 min · a written show
- Challenge 1–327 min · random, colour, an input doing two jobs
- Extrabonus · a wave across the sky
Review — where we got to 5 min
define launchholds the work; the script calls it.- One definition means one place to change.
- A block can call another block.
Quick-fire
Your launch block fires in a random place. You want one exactly in the middle, for the finale. What can you do about it right now?
Reveal the answer
Nothing tidy. You would have to make a second block, or edit the definition between calls. Today’s answer is to let the call carry the number.
Today’s Topic 3 min
- Inputs — adding a slot to your own block
define launch (x) (height) (sparks)- Reading an input inside the definition
- One block that makes every firework in the show
Learning outcome
By the end of this lesson you will be able to:
- Add number inputs to a My Block.
- Use an input inside the definition, including in a sum.
- Write a show as a list of calls with different numbers.
Learnt — telling your block what to do 28 min
1 · Adding an input
- Right-click your
define launchhat and choose Edit. - Click Add an input: number or text.
- Type
xover the name it suggests. - Click OK.
- The hat now reads
define launch at (x), with an orange oval in it.
That orange oval is the input. Drag a copy of it out of the hat and into the go-to block, and the block will use whatever number the call gives it:
define launch at (x)
show
set size to (45) %
go to x: (x) y: (-170)
glide (0.4) secs to x: (x) y: (90)
hide
repeat (14)
create clone of [myself v]
end
(x) in the go-to is dragged from the hat. It is not a variable.
when flag clicked
launch at (-150) :: custom
wait (0.7) seconds
launch at (0) :: custom
wait (0.7) seconds
launch at (150) :: custom
How to use this: Click the green flag: left, middle, right. One definition did all three.
2 · Three inputs
Add two more the same way — height and sparks — and the block can make any firework you can describe:
define launch (x) (height) (sparks)
show
set size to (45) %
go to x: (x) y: (-170)
glide (0.4) secs to x: (x) y: (height)
hide
repeat (sparks)
create clone of [myself v]
end
repeat (sparks) is the one that surprises people — an input can go anywhere a number can.
launch (-140) (50) (8) :: custom
launch (0) (120) (26) :: custom
How to use this: Click the green flag: a small one, a big one, a middling one — all from the same block.
3 · The order of the slots matters
launch (0) (120) (26) :: custom means x 0, height 120, sparks 26. Swap two numbers and you get a firework 26 pixels up with 120 sparks in it — which is a mess, and Scratch will not warn you.
Basic — a written show 24 min
Open your show from last lesson.
Step 1 — add the inputs
- Right-click the define hat, Edit, and add three number inputs.
- Call them
x,heightandsparks.
Step 2 — use them
- Drag the x oval into both the go-to and the glide.
- Drag the height oval into the glide’s y.
- Drag the sparks oval into the repeat.
- Take out the pick-random blocks you had there.
Step 3 — write the show
- Delete the repeat loop under the green flag.
- Put five calls there instead, one per firework.
- Give them numbers that build: low at the edges, high in the middle.
Step 4 — pace it
- Put
wait (0.5) secondsbetween the calls. - Try 0.2 and 1.2 as well, and pick the one that looks best.
Step 5 — read it back
- Look at your script without running it.
- Can you tell what the show looks like? If not, the numbers need comments.
when flag clicked
launch (-160) (60) (10) :: custom
wait (0.5) seconds
launch (-80) (100) (16) :: custom
wait (0.5) seconds
launch (0) (140) (30) :: custom
wait (0.5) seconds
launch (80) (100) (16) :: custom
wait (0.5) seconds
launch (160) (60) (10) :: custom
How to use this: Click the green flag and watch the arch build from the left.
Every firework is in the same place.
The go-to still has a typed number in it instead of the x oval. Drag the oval from the define hat.
A firework has no burst at all.
Its sparks slot is empty, which counts as 0 — so repeat (0) makes nothing.
The rocket goes sideways.
The glide’s x is a different input from the go-to’s x, or one of them is still random. Both must be the same oval.
My calls have four slots and I only made three inputs.
You added one and then deleted the wrong thing. Edit the block and check the hat — what is in the hat is what the calls will show.
A different sky every time
Put random numbers in the call rather than in the definition.
- Six fireworks, all in random places, at random heights, in random sizes.
- The definition has no pick-random in it at all.
- Press the flag twice and get two different shows.
How to use this: Click the green flag, then press it again. Six fireworks, never the same twice.
Teacher note
This is the argument for inputs in one screen. With the random inside the definition you can only have chaos; with it in the call you can have chaos and control, from the same block.
Colour it
A fourth input: what colour the sparks should be.
define launch (x) (height) (sparks) (colour)- Three fireworks in three obviously different colours.
- The sparks get the colour, not just the rocket.
How to use this: Click the green flag and watch three bursts in three colours.
Teacher reveal — why an input will not reach the clones
define launch (x) (height) (sparks) (colour)
set [shade v] to (colour)
...
when I start as a clone
set [color v] effect to (shade)
🔥 An input only exists inside its own definition — the when I start as a clone script is a different script and cannot see it. So the block copies the input into a variable, and the clones read that. This is the first time the limits of an input really bite, and it is worth five minutes.
One input, two jobs
Make the higher fireworks automatically bigger, with one fewer input.
- Take the
sparksinput away. - Work the burst size out from the height instead.
- A low firework is small, a high one is big, and the show looks better for it.
How to use this: Click the green flag: low and small, high and big, middling and middling.
Teacher reveal
define launch (x) (height)
...
repeat ((height) / (6))
create clone of [myself v]
end
An input can go inside an operator, exactly like a variable. Ask what happens at height 6 (one spark) and at height 180 (thirty) — and whether ([floor v] of ((height) / (6))) would be tidier. It would.
A wave across the sky
Seven fireworks that walk from the left edge to the right, each one a little higher than the last — from one loop and one block.
- A counter that goes 1 to 7.
- The x and the height are worked out from the counter.
- You wrote one call, not seven.
How to use this: Click the green flag and watch the wave cross the sky, climbing as it goes.
Teacher reveal
set [n v] to (0)
repeat (7)
change [n v] by (1)
launch ((-210) + ((n) * (52))) ((50) + ((n) * (10))) (12) :: custom
wait (0.35) seconds
end
Two nested operators inside a call slot, which is a lot to build and worth doing together. The pupils who get this have joined Lesson 3-1’s nesting to today’s inputs, and that is the whole of Level 3’s first half in one block.
Summary 5 min
- Edit a My Block to add inputs:
define launch (x) (height) (sparks). - The orange ovals in the hat are dragged into the body to be used.
- An input can go anywhere a number can — including inside a repeat or a sum.
- An input only exists inside its own definition. To reach a clone script, copy it into a variable.
- The order of the slots is the order of the inputs, and nothing warns you.
- Input
- A slot on your block that the call fills in.
- Argument
- The value handed over in that slot.
- Parameter
- The orange oval inside the definition that receives it.
- Reusable
- One block that does a whole family of jobs.
Hand in
Save your show. Next lesson you meet the tickbox at the bottom of the Make a Block window — the one that turns a burst from a dribble into a bang.