- 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 to count.
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. It says how you did.
Quick-fire
Every muffin in your stall is worth one point. What does that mean for the player?
Reveal the answer
The player never has to choose. Two muffins fall, both worth one. You just go for the nearer one. Games are more fun when the player has to choose.
Today’s Topic 3 min
- The Sound tab, and picking a sound from the library
play sound [Pop v]andplay sound [Pop v] until done, and which one a game needs- 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 in a falling loop.
- Give two falling things different values. Make it easy to see which is which.
Learnt — sound, value, and a trap 27 min
Sounds live on a sprite
Every sprite has its own sounds. They are in the Sound tab, next to Costumes. The cat comes with Meow. Everything else starts with Pop.
- Click your muffin sprite. Then click the Sound tab at the top left.
- Put the mouse on the speaker button at the bottom. 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 goes straight on. The script never waits. |
play sound [Pop v] until done | Sound | Starts the sound. The script waits until the sound has finished. |
In a falling loop, this matters a lot. Say a muffin runs play sound [Bubbles v] until done. It 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: in a loop, or in anything the player is watching, use play sound [Pop v]. Keep “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
You need no new block to make a muffin worth three points. It is change [score v] by (3). It is the same block, with a different number.
Planning the game is harder than the code. What if the special muffin is as easy to catch as the others? Then there is no choice to make. It is just a gift. So 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 round. 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 the others. Only the caught path is different. And nothing happens on the missed path.
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). Missing it costs nothing.Basic — give the stall a voice 25 min
Open your game from last lesson. Test after every step, with the sound 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. Put it above the score block. - Play. Every catch should pop. Nothing should stop and start.
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 the sound.
Step 3 — the valuable muffin
- Right-click your second muffin sprite. Check that it has its own falling stack.
- Change its score block to
change [score v] by (3). - Add Coin to it. Play that, not Pop.
- Make it harder. Use
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, like the muffin.
- On its caught path, put
play sound [Boing v]andchange [lives v] by (-1). - Put only the delete on its missed path.
- Make it come less often than the muffin. Use a wait of 3 or 4 seconds.
Step 5 — play it properly
- Play a full game, all the way to game over.
- Did you ever choose to move away from something? If not, the beetle does not come often enough.
- Did you ever leave the cake? If not, it is not worth enough points.
My muffin stops half way down.
That is play sound [Pop v] until done. Use the plain one instead.
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 that the sound is on the sprite that plays it. Check that the dropdown shows its name, not Meow. A sprite can only play its own sounds.
A sound for every moment
Three things in your game should make a sound. They are a catch, a miss, and the end.
- Three different sounds, one for each moment.
- None of them makes the game wait.
- You can tell them apart with your eyes shut.
Worth going for
Make one kind of muffin worth a lot more than the others. Make it really harder to get, too.
- At least two values. The big one is at least three times the small one.
- The special one is harder to get. It is smaller or quicker, or it falls near 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 the player must not catch. It could be a beetle, a stone or a chilli. It must clearly not belong.
- Catching it costs a life and makes a bad sound.
- Letting it land costs nothing.
- It looks nothing like the things you want.
- It does not come often. So 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 you can play by ear. Music plays all the time. Every event has a sound. The music 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 plays again and again, with no gaps.
- A different sound for a catch, a miss, and the beetle.
- The music gets quieter as lives run out.
- With the sound off, the game still plays just as before.
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
Now each thing in your stall means something different.
play sound [Pop v]starts a sound and goes on.play sound [Pop v] until donewaits. It stops anything that is falling.- A muffin is worth more because of the number in
change [score v] by (1). 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 are, next to Costumes. The Stage has one too.
- play sound
- Starts a sound and goes straight on. The right one for a game.
- until done
- Makes the script wait until the sound ends. 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 last part. The game speeds up as you win. It ends on a real Game Over screen. And it remembers your best score.