- Learnt27 min · sound blocks, values, and a trap
- Basic25 min · give your stall a voice
- Challenge 1–327 min · sound it, price it, dodge it
- Extrabonus · play it with your eyes shut
Review — where we got to 5 min
Last lesson the stall started counting.
change [score v] by (1)on the caught path.change [lives v] by (-1)on the missed path.wait until <(lives) = (0)>ends the game and says how you did.
Quick-fire
Every muffin in your stall is worth exactly one point. What does that mean for the player?
Reveal the answer
There is never a decision to make. Two muffins falling, both worth one, and you go for the nearer one. Games get interesting when the player has to choose.
Today’s Topic 3 min
- The Sound tab, and choosing a sound from the library
play sound [Pop v]andplay sound [Pop v] until done— and which one a game wants- Different numbers in
change [score v] by (1) - A falling thing that costs a life if you catch it
Learning outcome
By the end of this lesson you will be able to:
- Add a sound to a sprite and play it at the right moment.
- Say why “until done” is wrong inside a falling loop.
- Give two falling things different values, and make the difference visible.
Learnt — sound, value, and a trap 27 min
Sounds live on a sprite
Every sprite carries its own sounds, in the Sound tab beside Costumes. The cat arrives with Meow. Everything else starts with Pop.
- Click your muffin sprite, then the Sound tab at the top left.
- Hover the speaker button at the bottom and pick Choose a Sound.
- Search for
Pop. Click it. It is now on this sprite. - Go back to the Code tab and open Sound. Your new sound is in the dropdown.
Two blocks, one important difference
| Block | Category | What it does |
|---|---|---|
play sound [Pop v] | Sound | Starts the sound and moves straight on. The script never waits. |
play sound [Pop v] until done | Sound | Starts the sound and holds the script until it has finished playing. |
In a falling loop, that difference is the whole game. A muffin running play sound [Bubbles v] until done stops in mid-air for two seconds while the sound plays.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
The rule: inside a loop, or in anything the player is watching, use play sound [Pop v]. Save “until done” for music, and for a sprite that has nothing else to do.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
Worth more, and harder to get
Making a muffin worth three points needs no new block at all. It is change [score v] by (3) — the same block, a different number.
The design part is harder than the code part. A valuable muffin that is just as easy to catch as the others is not a decision, it is a gift. Make it smaller, or quicker, or make it fall near the edges.
if <touching [Bowl v]?> then
play sound [Pop v]
change [score v] by (1)
delete this clone
end
if <touching [Bowl v]?> then
play sound [Coin v]
change [score v] by (3)
delete this clone
end
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
The one you must not catch
Now turn it around. A beetle has got into the stall. Catch it and you lose a life. Let it land and nothing happens.
This is the same falling stack as everything else. Only what it does on the caught path is different, and it has no missed path at all.
when I start as a clone
show
go to x: (pick random (-200) to (200)) y: (170)
repeat (34)
change y by (-10)
if <touching [Bowl v]?> then
play sound [Boing v]
change [lives v] by (-1)
delete this clone
end
end
delete this clone
change [score v] by (1), and no cost for missing it.Basic — give the stall a voice 25 min
Open your game from last lesson. Test after every step, with the volume up.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
Step 1 — a sound for catching
- Click the muffin. Open the Sound tab and add Pop.
- Back in Code, put
play sound [Pop v]inside the touching-if, above the score block. - Play. Every catch should pop, and nothing should stutter.
Step 2 — a sound for missing
- Add Squeaks to the same sprite.
- Put
play sound [Squeaks v]below the repeat, next to the lives block. - Let one land. You should hear it go.
Step 3 — the valuable muffin
- Right-click your second muffin sprite and check it has its own falling stack.
- Change its score block to
change [score v] by (3). - Add Coin to it and play that instead of Pop.
- Make it harder:
set size to (60) %, and a bigger number in its change y.
Step 4 — the beetle
- Add the Beetle sprite.
- Give it the maker stack and the falling stack, the same as the muffin.
- On its caught path, put
play sound [Boing v]andchange [lives v] by (-1). - Leave its missed path with nothing but the delete.
- Make it come less often than the muffin — a wait of 3 or 4 seconds.
Step 5 — play it properly
- Play a full game, to the game over.
- Did you ever choose to move away from something? If not, the beetle is too rare.
- Did you ever ignore the cake? If not, it is not valuable enough.
My muffin stops half way down.
That is play sound [Pop v] until done. Swap it for the plain one.
The beetle takes a life even when I dodge it.
You put the change [lives v] by (-1) below the repeat as well as inside the if. The beetle only costs you when it is caught.
I cannot hear anything.
Check the sound is on the sprite that plays it, and check the dropdown says its name and not Meow. A sprite can only play sounds it owns.
A sound for every moment
Three things happen in your game that the player should be able to hear: a catch, a miss, and the end.
- Three different sounds, one per moment.
- None of them holds the game up.
- You can tell them apart with your eyes shut.
Worth going for
Make one kind of muffins worth a lot more than the others — and make it genuinely harder to get.
- At least two values, and the big one is at least three times the small one.
- The valuable one is harder: smaller, quicker, or falling nearer the edges.
- Its sound is different, so you know what you got without looking at the score.
Teacher note — the number that makes it a decision
If the valuable muffin is worth 2, nobody changes course for it. At 5 everybody does, and the easy ones stop mattering. Somewhere around 3 is where the choice gets interesting, and letting pupils find that by playing is worth more than telling them.
The thing you must not catch
Put something in your stall that punishes the player for catching it. A beetle, a stone, a chilli. Anything that clearly does not belong.
- Catching it costs a life and makes a bad noise.
- Letting it land costs nothing.
- It looks nothing like the things you want.
- It comes rarely enough that catching one feels like a mistake, not bad luck.
Teacher reveal — the whole beetle
when flag clicked
hide
forever
wait (4) seconds
create clone of [myself v]
end
when I start as a clone
show
go to x: (pick random (-200) to (200)) y: (170)
repeat (34)
change y by (-10)
if <touching [Bowl v]?> then
play sound [Boing v]
change [lives v] by (-1)
delete this clone
end
end
delete this clone
It is the muffin stack with two blocks swapped. The lesson here is that a completely different game feeling came from changing what happens on one path.
Play it with your eyes shut
Make a version of your stall that can be played by ear. Music underneath, a sound for every event, and music that tells you when you are in trouble.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
- Background music that loops with no gap and no stutter.
- A different sound for a catch, a miss, and the beetle.
- The music gets quieter as lives run out.
- The game still plays exactly as before with the sound off.
Teacher notes — where each piece goes
The music is the one place play sound [Garden v] until done is right, because a forever around it is what makes it loop with no gap:
when flag clicked
set volume to (100) %
forever
play sound [Garden v] until done
end
when flag clicked
wait until <(lives) = (1)>
set volume to (30) %
Put both on the Stage rather than a sprite. The Stage has a Sound tab too, and music that belongs to nobody in particular belongs there.
Going further: change [pitch v] effect by (10) would let the music rise as the score climbs. It is in the same drawer, and nobody has met it yet.
Summary 4 min
Everything in your stall now means something different.
play sound [Pop v]starts a sound and moves on.play sound [Pop v] until donewaits, and freezes anything that is falling.- A muffin is worth more because of the number in
change [score v] by (1), and it is fair because it is harder to catch. - A thing you must not catch is the same stack with a different caught path.
- Sound tab
- Where a sprite’s own sounds live, beside Costumes. The Stage has one too.
- play sound
- Starts a sound and carries straight on. The right one for a game.
- until done
- Holds the script until the sound has finished. Right for music, wrong in a loop.
- Value
- What one catch is worth. Two kinds with two values give the player a choice.
Next lesson: the finale. It speeds up as you win, it ends on a proper Game Over screen, and it remembers your best.