- Learnt28 min · or, not, one watcher, a beep
- Basic24 min · snakes and sound
- Challenge 1–327 min · a third snake, silence, safe holes
- Extrabonus · a beep that rises
Review — where we got to 5 min
<<> and <>>says yes only when both sides say yes.- Warm is a range: more than 60, and less than 150.
<() = ()>ended the game at exactly 0 digs.
Quick-fire
The detector is exactly 60 steps from the chest.
Hot! asks <(distance to [Treasure v]) < (60)>. Warm asks for more than 60. Which word does it say?
Reveal the answer
Neither! 60 is not less than 60. It is not more than 60 either. So the detector keeps whatever word it said last.
It almost never happens, because distances are rarely a whole number. Today’s new block, <not <>>, can fix it.
Today’s Topic 3 min
<<> or <>>— either question is enough<not <>>— turns yes into no, and no into yes- Two snakes that cost you a dig
- No digging twice in the same hole
- A beep that gets faster as you close in
Learning outcome
By the end of this lesson you will be able to:
- Join two questions with or.
- Flip a question with not.
- Use a changing number to set how long a wait is.
Learnt — or, not, and a beep 28 min
1 · Two snakes
A treasure hunt needs danger. Add two snakes that slide across the sand.
- Add the
Snakesprite from the library. - In its direction dial, pick the left/right arrows. Now it never turns upside down.
- Give it the stack below.
- Duplicate it. The copy is called
Snake2. - Change Snake2 to start at x: 170, y: -140, and slide the other way in 4 seconds.
when flag clicked
go to x: (-170) y: (-70)
forever
point in direction (90)
glide (5) secs to x: (170) y: (-70)
point in direction (-90)
glide (5) secs to x: (-170) y: (-70)
end
2 · or: either one is enough
The detector must ask about two snakes. Touching Snake is bad. Touching Snake2 is bad too. One question can hold both: <<> or <>>.
| Touching Snake? | Touching Snake2? | or says |
|---|---|---|
| yes | yes | yes |
| yes | no | yes |
| no | yes | yes |
| no | no | no |
Compare it with and from last lesson. And needs both. Or needs just one.
when flag clicked
forever
if <<touching [Snake v]?> or <touching [Snake2 v]?>> then
change [digs left v] by (-1)
start sound [Bonk v]
wait (1) seconds
end
end
How to use this: Click the green flag, then move the mouse onto a snake's path. When the detector touches a snake you hear a bonk and lose a dig. Nothing else to press.
3 · One script watches the digs
Two scripts take digs away now: the dig and the snakes. The check for 0 was inside the dig script. So a snake could take the last dig, and nobody would notice.
Give the job to one script that only watches:
when flag clicked
set [digs left v] to (5)
wait until <(digs left) < (1)>
broadcast [lost v]
4 · not: no digging twice
Right now you can press on an old hole and lose another dig. A hole you already dug is empty! A dig should only count where there is not a hole.
<not <>> flips a question. Yes becomes no. No becomes yes.
<touching [Hole v]?> | <not <touching [Hole v]?>> |
|---|---|
| yes — on an old hole | no — do not dig |
| no — fresh sand | yes — dig |
when flag clicked
set [digs left v] to (5)
forever
go to [mouse-pointer v]
end
when flag clicked
forever
if <mouse down?> then
if <not <touching [Hole v]?>> then
change [digs left v] by (-1)
create clone of [Hole v]
end
wait until <not <mouse down?>>
end
end
How to use this: Click the green flag, then press the mouse button to dig a hole. Press again on the same hole: nothing happens. Dig somewhere new and one dig is used.
5 · A beep that speeds up
Real detectors beep. The closer they get, the faster they beep. We can do that with one wait.
The wait between beeps is the distance divided by 200. Divide is in Operators: (() / ()).
| Distance | Wait between beeps |
|---|---|
| 400 | 2 seconds |
| 200 | 1 second |
| 40 | 0.2 seconds |
when flag clicked
forever
start sound [Computer Beep v]
wait ((distance to [Treasure v]) / (200)) seconds
end
How to use this: Click the green flag, then move the mouse slowly towards the chest. Listen: the beeps get faster. Nothing else to press.
Basic — snakes and sound 24 min
Open your hunt from last lesson. Add one thing at a time, and play after each.
How to use this: Click the green flag, then move the mouse over the sand and listen to the beep. Press the mouse button to dig. Keep the detector away from the two snakes.
Step 1 — the snakes
- Add Snake, set its dial to left/right, and give it its stack.
- Duplicate it and change Snake2’s numbers.
- Play. Two snakes slide past each other.
Step 2 — the bite
- Add the
Bonksound to the Detector. - Build the snake script with
<<> or <>>. - Play. Touch each snake once. Both cost a dig.
Step 3 — one watcher
- In the dig script, delete the
if / thenthat asked<(digs left) = (0)>. - Move
set [digs left v] to (5)out of the dig script. - Build the watcher script with it.
- Lose to the snakes on purpose. The game must end.
Step 4 — no digging twice
- In the dig script, wrap the Hot!
if / elseinside a newif / then. - Its question:
<not <touching [Hole v]?>>. - Play. Press twice on the same hole. The second press does nothing.
Step 5 — the beep
- Add the
Computer Beepsound to the Detector. - Build the beep script.
- Close your eyes. Can you find the chest by sound alone?
The Detector’s new and changed scripts
when flag clicked
forever
if <mouse down?> then
if <not <touching [Hole v]?>> then
if <(distance to [Treasure v]) < (60)> then
broadcast [found v]
else
change [digs left v] by (-1)
create clone of [Hole v]
end
end
wait until <not <mouse down?>>
end
end
when flag clicked
forever
if <<touching [Snake v]?> or <touching [Snake2 v]?>> then
change [digs left v] by (-1)
start sound [Bonk v]
wait (1) seconds
end
end
when flag clicked
forever
start sound [Computer Beep v]
wait ((distance to [Treasure v]) / (200)) seconds
end
when flag clicked
set [digs left v] to (5)
wait until <(digs left) < (1)>
broadcast [lost v]
A snake takes all my digs at once.
The wait (1) seconds is missing, or it is outside the if. It must come after the bonk, inside the if.
Only Snake bites. Snake2 never does.
Both sides of the or say Snake. Change the second dropdown to Snake2.
The snakes take my last dig, but the game goes on.
The <(digs left) = (0)> check is still in the dig script, and the watcher is missing. Build the watcher.
The beep never gets fast.
You used play sound [Computer Beep v] until done. Swap it for start sound [Computer Beep v].
I can never dig at all.
The original Hole is showing and sitting under the detector. Check the Hole’s flag script says hide.
A third snake
Two snakes is not enough. Add a third.
- Snake3 slides along its own path, between the other two.
- Touching any of the three snakes costs a dig.
- There is still only one bite script.
Teacher reveal — an or inside an or
if <<touching [Snake v]?> or <<touching [Snake2 v]?> or <touching [Snake3 v]?>>> then
change [digs left v] by (-1)
start sound [Bonk v]
wait (1) seconds
end
or only has two slots. So the second slot holds another or. Some pupils build three separate ifs instead. That works, but a snake touching two at once then bites twice — worth asking about.
Silent when cold
A beep far away is just noise. Keep it quiet until you are getting close.
- When the detector is Cold, there is no beep at all.
- Once it is Warm or Hot!, the beeping starts.
- It still gets faster as you close in.
How to use this: Click the green flag, then move the mouse from far away towards the chest. Far away it is silent; once it says Warm, it beeps. Nothing else to press.
Teacher reveal — not more than 150
when flag clicked
forever
if <not <(distance to [Treasure v]) > (150)>> then
start sound [Computer Beep v]
end
wait ((distance to [Treasure v]) / (200)) seconds
end
“Not more than 150” is the same as “150 or less”. Scratch has no “less than or equal to” block, so this is how to say it. Pupils who write <(distance to [Treasure v]) < (150)> are right too, apart from exactly 150.
The wait stays outside the if. Otherwise a Cold loop would spin with no pause.
Safe in a hole
A hole is a good place to hide from a snake. Make it a safe spot.
- A snake still bites on open sand.
- While the detector is in a hole, snakes slide past with no bite.
- So an old hole on a snake’s path becomes a place to wait.
How to use this: Click the green flag, then press the mouse button on a snake's path to dig a hole. Keep the detector in the hole: the snake slides past without biting.
Teacher reveal — and, or and not in one question
when flag clicked
forever
if <<<touching [Snake v]?> or <touching [Snake2 v]?>> and <not <touching [Hole v]?>>> then
change [digs left v] by (-1)
start sound [Bonk v]
wait (1) seconds
end
end
All three of the week’s blocks in one line. Read it aloud: “touching a snake, and not in a hole”. Say which block goes on the outside, and why.
A beep that rises
Faster is good. Higher as well is better. Make the beep climb as you close in.
- Far away, the beep is low.
- Close to the chest, it is high.
- It still gets faster, as before.
How to use this: Click the green flag, then move the mouse slowly towards the chest. Listen: the beep gets faster and higher as you close in. Nothing else to press.
Teacher reveal — pitch from distance
when flag clicked
forever
set [pitch v] effect to ((200) - (distance to [Treasure v]))
start sound [Computer Beep v]
wait ((distance to [Treasure v]) / (200)) seconds
end
At 0 steps the pitch is 200, which is high. At 400 steps it is -200, which is low. The same number drives the speed and the note — that is the idea to name.
Summary 5 min
<<> or <>>says yes when either side says yes. And needs both.<not <>>flips a question: yes becomes no.- When two scripts change a number, give one script the job of watching it.
- A wait can use a changing number. Distance divided by 200 makes a beep speed up.
- or
- Joins two questions. Either one being true is enough.
- not
- Turns true into false, and false into true.
- Trap
- Something in a game that costs you when you touch it.
- Watcher
- A script whose only job is to wait for a number and react.
Hand in
Save your hunt. Next lesson: three chests against the clock, a best time, and a start screen.