- Learnt28 min · a score, and a best that outlives it
- Basic24 min · the whole game
- Challenge 1–327 min · the wiped best, a results card, a difficulty menu
- Extrabonus · ship it
Review — the arc so far 5 min
- A
statevariable names the situation, and every script asks it. - Lives, a
hurtflag so one touch is not sixty, and a reset in the script that owns it. wait until <(state) = [play]>at the top of every loop is pause.
Quick-fire
You want a high score that survives playing again. Which script sets it back to 0 — the green flag, or the start of a round?
Reveal the answer
The green flag. It outlasts a round, so it belongs with the things the flag sets up. Put it in the round and you get Challenge 1.
Today’s Topic 3 min
- Scoring from clones you fly through
best, and the two-line shape that keeps it- A results card built with
join - A menu state, and a setting it carries into the game
Learning outcome
By the end of this lesson you will be able to:
- Keep a score for the round and a record for the session.
- Report a run in a way a player actually wants to read.
- Add a state to a machine that already works, without breaking it.
Learnt — points, and a record 28 min
1 · Something worth flying towards
Dodging alone is thin. Stars drift in from the right; flying through one scores a point. They are clones, exactly like the bubbles in the last arc:
when I start as a clone
show
set size to (55) %
repeat until <(x position) < (-225)>
wait until <(state) = [play]>
change x by (-11)
if <touching (Parrot v)?> then
change [score v] by (1)
delete this clone
end
end
change [missed v] by (1)
delete this clone
missed line, because the delete happened first.How to use this: Click the green flag and steer through the stars with the arrow keys.
2 · The best score
Two variables, and the whole difference is where each one is reset:
when flag clicked
set [best v] to (0)
set [rounds v] to (0)
when I receive [start v]
set [state v] to [play]
set [score v] to (0)
set [lives v] to (3)
Then at the end of the round, the shape you have now met three times:
set [state v] to [over]
if <(score) > (best)> then
set [best v] to (score)
say [A new best!] for (0.8) seconds
end
How to use this: Click the green flag and let three rounds play out. Watch best against score.
Basic — the whole game 24 min
Open last lesson’s Storm Flight. Everything is in place except a reason to care about the score.
Step 1 — the variables
- Make
scoreandbest, both for all sprites. bestis set to 0 under the green flag, and nowhere else.scoreis set to 0 in thestartscript, with the lives.
Step 2 — the stars score
- In the star clone’s drift loop, add the touching test and
change [score v] by (1). - Delete the clone straight after, or one star scores over and over — the same per-frame problem as Lesson 3-22.
Step 3 — bolts as clones too
- Give the Bolt the same spawner-and-clone shape as the Star.
- Bolts drift faster than stars, and never delete on touching — they cost a life.
- Both clone loops need
wait until <(state) = [play]>.
Step 4 — the ending
- The round loop ends when lives reach 0:
repeat until <(lives) = (0)>. - Set the state to over, then run the best-score check.
- Bring the parrot to the middle, make it bigger, and report the score and the best.
set [state v] to [over]
if <(score) > (best)> then
set [best v] to (score)
end
go to x: (0) y: (0)
set size to (70) %
say (join [GAME OVER - ] (join (score) (join [ stars. Best ] (best)))) for (2.5) seconds
say [Space for the title.] for (1.5) seconds
join inside join — three pieces of text and two numbers in one sentence.How to use this: Click the green flag, press space, fly for stars and dodge bolts. P pauses.
One star scores dozens of points.
The clone is not deleted when it is caught, so the touching test is true on every frame it overlaps.
The score keeps rising after the game is over.
The star clones from the last round are still drifting. Delete them when the state leaves play, or let the round’s end delete them.
Best is always the same as score.
set [best v] to (0) is in the round script. That is Challenge 1.
The say bubble shows the words but not the numbers.
You typed the variable’s name into the text instead of dragging the orange oval in. The bubble should show a rounded orange block sitting inside the join.
Everything freezes when I pause, except the score.
Good — that is correct. The score is a number, not a movement; there is nothing for it to do while paused.
The wiped best
Put set [best v] to (0) in the round script and play three rounds.
- Three rounds, back to back.
- Watch
bestafter each one. - Write down, in one sentence, what best is actually measuring now.
How to use this: Click the green flag and watch best at the end of each of the three rounds.
Teacher note
The answer to “what is it measuring?” is this round’s score, which is the reason the bug is so quiet: the number is never absurd, just useless. Contrast it with the negative lives in 3-22, which announce themselves. Some bugs shout and some whisper, and the whispering ones need this kind of deliberate test.
A card worth reading
One number is a result. Four is a story. Report the whole run.
- Stars caught, and stars missed.
- How long you survived, in real seconds.
- The best so far, for comparison.
- All of it in two lines, built with
join.
How to use this: Click the green flag, fly for a few seconds, and read the two-line card at the end.
Teacher reveal — making the seconds honest
repeat (24)
wait until <(state) = [play]>
next costume
wait (0.25) seconds
change [my time v] by (0.25)
end
The wait is what makes the number true. Without it the loop runs at full speed and adds a quarter each time, so a one-second run reports six seconds — a number that looks like a time and is not one. Quarters also avoid the 0.1 problem from last lesson.
A difficulty menu
Add a fifth state between the title and the game, and let the player choose.
- A
menustate. Keys 1, 2 and 3 setdifficultyto a word. - Each choice also sets
bolt speedto a number. - Space leaves the menu and starts the round.
- The bolts read that number all through the round.
How to use this: Click the green flag, press 1, 2 or 3 to choose, then space to fly.
Teacher reveal — why the number and the word are separate
when [3 v] key pressed
if <(state) = [menu]> then
set [difficulty v] to [hard]
set [bolt speed v] to (11)
end
The word is for the player and the card; the number is for the bolts. This is the other half of Lesson 3-21’s argument — words where people read them, numbers where the code needs to calculate. And the if guard is why pressing 3 mid-flight cannot change the difficulty under you.
Ship it
Put the whole arc into one game you would hand to somebody else to play.
- A title, then a menu, then the game.
- Three lives, a hurt flag, and a pause that works everywhere.
- Stars to catch and bolts to dodge, both as clones.
- A score card, and a best that survives every round.
How to use this: Click the green flag, pick a difficulty, and fly. P pauses, space restarts.
Teacher note
The paper diagram is the deliverable, not the game. A pupil who can draw their own state machine has the idea; one who cannot has a working game by accident. Lesson 3-45 comes back to exactly this with a planning sheet.
Summary 5 min
- Delete a collectable clone the moment it is caught, or it scores every frame.
scoreis reset by the round;bestis reset by the flag. That one difference is the whole high-score feature.if <(score) > (best)> thenis the same shape you have used in three arcs now.joininsidejoinputs several numbers in one sentence.- A new state is safe to add if every script already asks — which is why the menu was easy and the pause was hard.
- High score
- The best result of the session, kept across rounds.
- Menu state
- A state whose only job is to let the player choose a setting.
- Setting
- A value chosen once and read throughout — like the bolt speed.
- Results card
- The report a game shows about the run you just played.
Hand in
Save your shipped game. You have finished the game-state arc — and every game you build from here has a title, a pause and a game over, because you now know how.