- Learnt28 min · and, ranges, equals, holes, losing
- Basic24 min · five digs to find it
- Challenge 1–327 min · four words, the sand, a hole map
- Extrabonus · warmer or colder
Review — where we got to 5 min
(distance to [Treasure v])works even when the chest is hidden.<() < ()>and<() > ()>ask a question. The answer is true or false.- The chain asks “under 60?” first, then “under 150?”.
Quick-fire
The chest is 100 steps away. Which word does the chain say?
Reveal the answer
Warm. “Under 60?” says no, so the else runs. Then “under 150?” says yes.
The Warm question is only asked because the Hot! one said no. Remember that.
Today’s Topic 3 min
<<> and <>>— two questions that must both say yes- A range: Warm is “more than 60 and less than 150”
<() = ()>— exactly the same- Five digs, and a hole for every dig
- The first way to lose
Learning outcome
By the end of this lesson you will be able to:
- Join two questions with and.
- Check if a number is inside a range.
- Count down to zero and end the game there.
Learnt — a range, and a limit 28 min
1 · Warm only works in the chain
Last lesson, Warm was asked second. Try asking it alone, in its own if / then:
if <(distance to [Treasure v]) < (150)> then
say [Warm]
end
Warm is not “under 150”. Warm is more than 60, and under 150. That is two questions, and both must say yes.
2 · and: both must say yes
<<> and <>> is a green Operators block. It has two pointy slots.
| Left question | Right question | and says |
|---|---|---|
| yes | yes | yes |
| yes | no | no |
| no | yes | no |
| no | no | no |
- Open Operators. Drag out
<<> and <>>. - Drop
<() > (50)>into the left slot. Type 60. - Drop
<() < (50)>into the right slot. Type 150. - Put
(distance to [Treasure v])in both empty ends.
<<(distance to [Treasure v]) > (60)> and <(distance to [Treasure v]) < (150)>>
3 · Three ifs, any order
Now each word has its own full question. They do not need the chain any more. Three plain if / then blocks will do.
when flag clicked
forever
go to [mouse-pointer v]
if <(distance to [Treasure v]) < (60)> then
say [Hot!]
end
if <<(distance to [Treasure v]) > (60)> and <(distance to [Treasure v]) < (150)>> then
say [Warm]
end
if <(distance to [Treasure v]) > (150)> then
say [Cold]
end
end
How to use this: Click the green flag, then move the mouse towards the chest and away again. Watch the detector say Hot!, Warm or Cold. Nothing else to press.
4 · Five digs, and exactly zero
Make a variable called digs left. Set it to 5 at the flag. Every dig takes one away.
When is the game over? When digs left is exactly 0. That is the third compare block, <() = ()>.
change [digs left v] by (-1)
if <(digs left) = (0)> then
broadcast [lost v]
end
5 · A hole for every dig
A dig should leave a mark. Each hole is a clone, like the zombies were.
- Paint a sprite called
Hole: a dark oval. - Give it
when flag clickedandhide. The original is never seen. - Add
when I start as a clone,go to [Detector v],show. - On the Detector, a dig does
create clone of [Hole v].
when flag clicked
set [digs left v] to (5)
forever
if <mouse down?> then
change [digs left v] by (-1)
create clone of [Hole v]
if <(digs left) = (0)> then
broadcast [lost v]
end
wait until <not <mouse down?>>
end
end
when flag clicked
hide
when I start as a clone
go to [Detector v]
show
How to use this: Click the green flag, then move the mouse over the sand. Press the mouse button five times in different places. Each press digs a hole and takes one dig away.
6 · Win, or lose
Put it together. A dig now asks one question first:
- Is it Hot!? Then
broadcast [found v], like last lesson. - If not, use up a dig and leave a hole.
When the digs reach 0, broadcast [lost v]. Two sprites listen:
when I receive [lost v]
stop [other scripts in sprite v]
say [Out of digs!]
when I receive [lost v]
show
Basic — five digs to find it 24 min
Open your hunt from last lesson. Change one thing at a time, and play after each.
How to use this: Click the green flag, then move the mouse over the sand. Press the mouse button to dig. You have five digs; a dig when it says Hot! finds the chest.
Step 1 — three ifs instead of a chain
- Pull the whole chain out of the forever loop.
- Build three
if / thenblocks: Hot!, Warm, Cold. - Warm gets the
<<> and <>>range. - Play with the chest showing. Check all three words.
Step 2 — the variable
- Make a variable
digs left, for all sprites. Tick it so it shows.
Step 3 — the dig script
- Start a second script on the Detector:
when flag clicked,set [digs left v] to (5),forever. - Inside: an
if / thenwith<mouse down?>. - Inside that: an
if / else. Hot! meansbroadcast [found v]. - Else:
change [digs left v] by (-1). - After the
if / else, addwait until <not <mouse down?>>. - Delete the old mouse-down check from the first script.
Step 4 — the holes
- Paint the Hole sprite and give it its two stacks.
- In the else, add
create clone of [Hole v]. - Play. Every miss leaves a hole.
Step 5 — losing
- After the clone, add an
if / thenasking<(digs left) = (0)>. Putbroadcast [lost v]inside. - Give the Detector and the Treasure their “lost” scripts.
- Lose on purpose. Five misses, then the chest appears.
The whole Detector
when flag clicked
forever
go to [mouse-pointer v]
if <(distance to [Treasure v]) < (60)> then
say [Hot!]
end
if <<(distance to [Treasure v]) > (60)> and <(distance to [Treasure v]) < (150)>> then
say [Warm]
end
if <(distance to [Treasure v]) > (150)> then
say [Cold]
end
end
when flag clicked
set [digs left v] to (5)
forever
if <mouse down?> then
if <(distance to [Treasure v]) < (60)> then
broadcast [found v]
else
change [digs left v] by (-1)
create clone of [Hole v]
if <(digs left) = (0)> then
broadcast [lost v]
end
end
wait until <not <mouse down?>>
end
end
when I receive [found v]
stop [other scripts in sprite v]
say [You found it!]
when I receive [lost v]
stop [other scripts in sprite v]
say [Out of digs!]
when I receive [lost v] and show.One click uses up all five digs.
The wait until <not <mouse down?>> is missing, or it is inside the else. It must sit after the if / else, so it runs for every dig.
It says Cold right next to the chest.
Look at the Warm range. One of the two signs is the wrong way round. It should be “more than 60” and “less than 150”.
The holes appear in the middle of the Stage.
The clone script says go to [random position v] or is missing its go to. Pick Detector in the dropdown.
I lose at the very start of the game.
set [digs left v] to (5) is missing, so the count starts at 0.
Very warm
Split Warm into two words.
- 60 to 100 steps says Very warm.
- 100 to 150 steps says Warm.
- Hot! and Cold do not change.
- The four ifs still work in any order.
Teacher reveal — two ranges
if <(distance to [Treasure v]) < (60)> then
say [Hot!]
end
if <<(distance to [Treasure v]) > (60)> and <(distance to [Treasure v]) < (100)>> then
say [Very warm]
end
if <<(distance to [Treasure v]) > (100)> and <(distance to [Treasure v]) < (150)>> then
say [Warm]
end
if <(distance to [Treasure v]) > (150)> then
say [Cold]
end
The shuffle test is the point. A pupil who kept the old chain will find their words break when reordered. That is the lesson landing.
Only on the sand
Hide the chest a new way, with go to [random position v]. That block can land anywhere — even in the sky.
- The chest must always land on the sand.
- The sand is between y = -150 and y = -40.
- If it lands in the wrong place, it tries again, until it gets it right.
How to use this: Click the green flag to start it. Nothing else to press — watch the chest land on the sand again and again.
Teacher reveal — a range on y
What your pupil builds, on the Treasure:
when flag clicked
hide
switch costume to [chest v]
go to [random position v]
repeat until <<(y position) > (-150)> and <(y position) < (-40)>>
go to [random position v]
end
What the embed above runs — the same search in a loop, so you can watch it land again and again:
when flag clicked
switch costume to [chest v]
forever
hide
go to [random position v]
repeat until <<(y position) > (-150)> and <(y position) < (-40)>>
go to [random position v]
end
show
wait (1) seconds
end
The same and as Warm, on a different number. A range is a range. Ask why the chest must hide while it searches: otherwise the misses flash across the sky.
A map of your digs
Five digs is not many. Make every miss tell you something.
- A hole dug somewhere Warm gets an orange rim.
- A hole dug somewhere Cold gets a blue rim.
- The rims stay, so the holes become a map.
How to use this: Click the green flag, then move the mouse over the sand. Press the mouse button to dig. Each hole comes out orange or blue. Five digs to find the chest.
Teacher reveal — the hole asks for itself
when I start as a clone
go to [Detector v]
if <(distance to [Treasure v]) < (150)> then
switch costume to [warm v]
else
switch costume to [cold v]
end
show
The Hole gets two more costumes, warm and cold. The clone measures its own distance to the chest. Nobody has to tell it — which is the idea worth naming.
Only Warm and Cold are needed. A Hot! dig finds the chest, so it never makes a hole.
Warmer or colder?
Real treasure hunters compare. Is this dig closer than the last one?
- Each new hole says Warmer! or Colder! for two seconds.
- Warmer! means closer than the last hole.
- The first hole of a game always says Warmer!.
How to use this: Click the green flag, then move the mouse over the sand. Press the mouse button to dig. Each new hole says Warmer! or Colder!.
Teacher reveal — last dig
when flag clicked
hide
set [last dig v] to (999)
when I start as a clone
go to [Detector v]
show
if <(distance to [Treasure v]) < (last dig)> then
set [last dig v] to (distance to [Treasure v])
say [Warmer!] for (2) seconds
else
set [last dig v] to (distance to [Treasure v])
say [Colder!] for (2) seconds
end
999 is bigger than any distance on the Stage. So the first dig is always closer. Why is the set before the say? A quick second dig would otherwise compare against the wrong number.
Summary 5 min
<<> and <>>is yes only when both sides say yes.- A range is two compares joined by and: more than one number, less than another.
- With full questions, three ifs work in any order. A chain does not.
<() = ()>asks if two things are exactly the same.- A clone that goes to the Detector marks where you dug.
- and
- Joins two questions. Both must be true.
- Range
- Everything between a low number and a high one.
- Equals
- Exactly the same number, no more and no less.
- Lose condition
- The rule that ends the game badly — here, no digs left.
Hand in
Save your hunt. Next lesson, snakes arrive — and the detector starts to beep.