- Learnt28 min · the goal, and three keys
- Basic24 min · the locked cheese
- Challenge 1–327 min · winning too early, key clones, a best time
- Extrabonus · fewest steps
Review — last lesson 5 min
old xandold ymake one wall check work in every direction.- Judge x and y separately and the sprite slides along walls.
- Never step further than your thinnest wall, or you tunnel through it.
Quick-fire
Your mouse can drive the maze perfectly. Why is it still not a game?
Reveal the answer
Nothing can be won and nothing can be lost. Today is the winning half; next lesson brings the losing half.
Today’s Topic 3 min
touching (Cheese v)?as a win condition- Collectables as clones, counted once each
- A win that is conditional — the cheese asks about the keys
- A best time, and why it needs an extra test
Learning outcome
By the end of this lesson you will be able to:
- End a game with a win as well as a stop.
- Make a collectable that cannot be collected twice.
- Keep a record that gets better by getting smaller.
Learnt — earning the cheese 28 min
1 · The simplest possible win
A goal is one sprite and one question, running in its own loop alongside the driving:
when flag clicked
forever
if <touching (Cheese v)?> then
set [state v] to [won]
say [The cheese! You win.] for (2.5) seconds
end
end
state variable from the Storm Flight arc, doing the same job in a different game.How to use this: Click the green flag and watch the mouse walk the maze and reach the cheese.
2 · Something to collect on the way
A maze with one goal is a corridor with extra steps. Three keys, hidden off the quick route, turn it into a decision about where to go.
How to use this: Click the green flag. The mouse takes the long way round — down the left wall and along the bottom.
3 · A collectable that cannot be taken twice
Each key is a clone, and the clone ends its own life when it is taken:
when I start as a clone
show
wait until <touching (Mouse v)?>
change [keys v] by (1)
delete this clone
wait until rather than a loop, and the delete is what stops it counting on every frame you stand on it.That delete is the same idea as the popped bubble in Lesson 3-19: a collectable that stays is a collectable that scores for ever.
Basic — the locked cheese 24 min
Open last lesson’s maze. You are giving it something to win.
Step 1 — the cheese
- Add a cheese sprite — or draw a yellow wedge — and put it in the far corner.
- Make sure it is not the wall colour. Anything teal in your maze is a wall.
Step 2 — the keys
- Add the
Keysprite. Under the flag it hides and becomes a spawner. - Go to the first hiding place,
create clone of [myself v], then the second, then the third. - Pick spots at least two corridors off the quick route.
Step 3 — collecting
- Add
when I start as a clone: show, thenwait until <touching (Mouse v)?>. - Then
change [keys v] by (1)anddelete this clone. - Set
keysto 0 under the green flag.
Step 4 — the lock
- In the win check, ask about both:
if <<touching (Cheese v)?> and <(keys) = (3)>> then. - If the keys are missing, say so instead of winning.
Step 5 — make the lock visible
- On the cheese, a forever loop: if
keysis 3,clear graphic effects; otherwiseset [ghost v] effect to (55). - Now the player can see that it is not ready yet.
How to use this: Click the green flag. The mouse detours for all three keys, and only then does the cheese count.
The keys never appear.
The spawner hides but the clone script has no show. A clone copies the hidden state of the original.
One key counts several times.
The delete this clone is missing, or it is inside a loop that never reaches it.
I collect keys just by walking the normal route.
They are too close to the path. Move them further — two corridors off is the rule that works.
The cheese wins even with no keys.
The and is missing from the check. That is Challenge 1.
The cheese stays faded after the third key.
The forever loop on the cheese has an if but no else, so nothing ever undoes the ghost effect.
The win you did not earn
Take the keys out of the win condition and walk straight to the cheese.
- The check asks only
touching (Cheese v)?. - The keys still exist, and still count, and are still visible.
- Take the quick route and report how many you had.
How to use this: Click the green flag. The mouse ignores every key and wins anyway.
Teacher note
Worth drawing out the general shape: the keys did not stop working, they were never consulted. A rule that is not checked is not a rule. This is the same bug as the lightning that struck during the title screen in 3-21 — something real in the project that nothing ever asks about.
Six crossings, three keys
Prove that a collected key stays collected.
- Collect all three.
- Then walk back and forth over one of the empty spots several times.
- The counter should not move.
How to use this: Click the green flag and watch the mouse cross the bottom corridor four extra times.
Teacher reveal — what deleting actually buys you
Beginners usually solve this with a variable per key — key1 taken, key2 taken — which works for three and collapses at thirty. Deleting the clone is the same idea done properly: the thing that must not be collected again simply no longer exists. Ask what they would do for thirty keys, and the point makes itself.
A best time
Run the maze three times and keep the fastest.
- A clock that only ticks while a run is happening.
- A
best timethat survives all three runs. - A new best announced when it happens.
How to use this: Click the green flag and watch three runs at three speeds, and the best of them.
Teacher reveal — the test every other best in this level does not need
if <<(best time) = (0)> or <(time) < (best time)>> then
set [best time v] to (time)
end
Every other record in Level 3 gets bigger when it improves, so starting it at 0 is safe — any score beats 0. A time gets smaller, and nothing is ever less than 0, so the first run would never register. The or is the fix: “there is no record yet, or this one is faster”. Ask them to remove it and watch the best stick at 0 for ever.
A neater alternative is to start best time at some impossibly large number like 9999. Both work; the or is honest about what it means.
Fewest steps
Time is not the only way to be good at a maze. Count the cells walked instead, and keep the smallest.
- A run that collects all three keys, and its step count.
- A run that goes straight to the cheese, and its step count.
- A
fewest stepsthat keeps the smaller.
How to use this: Click the green flag and watch two runs, the long way and the short way.
Teacher note
A trap worth mentioning, because the first version of this demo fell into it: counting corners rather than cells made the detour look shorter than the direct route. If a measurement gives a surprising answer, check what it is actually counting before believing it.
Summary 5 min
touching (Cheese v)?plus a state change is a win.- A conditional win asks about more than one thing:
<touching (Cheese v)?> and <(keys) = (3)>. - A collectable deletes itself, so it cannot be taken twice.
- Hide collectables at least two corridors off the quick route.
- A best time improves by going down, so it needs an “or there is no record yet” test.
- Make a lock visible. A faded cheese explains itself; a silent one does not.
- Win condition
- The test that decides the game has been won.
- Collectable
- Something picked up once and then gone.
- Gated goal
- A goal that only counts once something else is done.
- Personal best
- The best result so far, kept across attempts.
Hand in
Save your maze. Next lesson something else moves in it — and it is looking for you.