- Learnt28 min · lives, the referee, and a pass mark
- Basic25 min · four questions, three lives
- Challenge 1–327 min · sudden death, a warning, three endings
- Extrabonus · Higher or Lower
Review — where we got to 5 min
Last week you built a show with three questions and a score. Two blocks from it matter today.
ask [] and wait, and the(answer)it leaves behind.if <> thenand itselsehalf, with<() = ()>in the diamond.
Quick-fire
Your quiz asks all three questions however badly the player does. What would make it stop early?
Reveal the answer
Something to lose, and something watching for it running out. You built both in the catching game — a lives variable and a script that checks it.
Today’s Topic 3 min
- A
livesvariable, and a wrong answer that takes one away - A script whose only job is to watch the lives
stop [this script v]— stopping one stack, not the whole show<() > ()>— a pass mark
Learning outcome
By the end of this lesson you will be able to:
- Take a life away when the player answers wrongly.
- End the show the moment the lives run out.
- Say whether the player passed, using a number you decide.
Learnt — lives, the referee, the pass mark 28 min
1 · A wrong answer costs a life
You already have the else branch. It runs every time the player is wrong. Put one more block in it.
- In Variables, make a variable called
lives. - On the green-flag stack, add
set [lives v] to (3). - In the else branch of your question, add
change [lives v] by (-1). - Run it and answer badly. Watch the number on the Stage go down.
when flag clicked
set [lives v] to (3)
ask [How many days are in a week?] and wait
if <(answer) = [7]> then
say [Correct!] for (2) seconds
else
change [lives v] by (-1)
say [Wrong. That costs a life.] for (2) seconds
end
How to use this: Click the green flag, then type your answer in the box and press Enter.
2 · Somebody has to notice
The lives can now reach zero, and nothing happens when they do. The show needs a referee: one script that does nothing but watch.
when flag clicked
set [lives v] to (3)
forever
if <(lives) = [0]> then
say [Out of lives! Show over.] for (3) seconds
stop [all v]
end
end
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
3 · The order inside a question
A referee in a forever loop works, but it can be a moment late — the next question may already be on screen. The tidier way is to check right there, in the question script.
when I receive [question 1 v]
ask [How many legs has a spider?] and wait
if <(answer) = [8]> then
change [score v] by (1)
else
change [lives v] by (-1)
end
if <(lives) = [0]> then
broadcast [out v]
stop [this script v]
end
broadcast [question 2 v]
4 · Did they pass?
A score of 3 out of 4 is a pass. A score of 1 is not. To tell them apart you need a new question shape: is one number bigger than another?
- Open Operators.
- Find
<() > ()>. It sits just above the equals block. - Drag
(score)into the left side. - Type your pass mark into the right side.
- Drop the whole thing into an if / else.
when I receive [result v]
if <(score) > [2]> then
say [You pass! Well done.] for (4) seconds
else
say [Not this time. Try again!] for (4) seconds
end
How to use this: Click the green flag, then type your answer in the box and press Enter.
Basic — four questions, three lives 25 min
Start from last week’s project. You are adding to it, not starting again.
Step 1 — the variable
- Make a variable called
livesand leave it showing. - Add
set [lives v] to (3)to the green-flag stack, under the score one.
Step 2 — one question at a time
- Open your question 1 script.
- Change the plain
if <> theninto anif / else. - Put
change [lives v] by (-1)in the else half. - Test it. Get it wrong. Watch the lives fall to 2.
Step 3 — the same in the others
- Do the same to questions 2, 3 and 4.
- Test after each one.
Step 4 — the out check
- Under the if / else in question 1, add
if <(lives) = [0]> then. - Inside it, put
broadcast [out v]andstop [this script v]. - Duplicate that if block into questions 2 and 3.
- Build the
when I receive [out v]script: a say block, thenstop [all v].
Step 5 — the pass mark
- Open your
when I receive [result v]script. - Wrap what is in it inside an if / else that tests the score.
- Decide your own pass mark and type it in.
Step 6 — play it three ways
- Answer everything right. You should pass.
- Answer everything wrong. The show should end after three.
- Get exactly your pass mark. Check that is the answer you wanted.
The show ends but keeps asking questions.
stop [this script v] is missing, or it is sitting under the broadcast instead of above it.
I never see the “Out of lives” message.
stop [all v] is running before the say block has finished. Use say [] for (3) seconds, then stop.
My second game starts with no lives.
The set-to-3 block is on the wrong stack. It belongs on the green flag, at the very start.
A score exactly on the pass mark fails.
That is what <() > ()> does. If you want the mark itself to pass, lower the number by one.
Sudden death
Make a version with six questions and only one life.
- Six questions.
- One life.
- One wrong answer ends the show immediately.
Warn them
A player should feel it coming. Make the host say something when they are down to their last life.
- The warning appears when lives reach 1, not before.
- It appears once, not over and over.
- It does not appear at all if they never get anything wrong.
Teacher note — the repeating warning
A warning put in the referee’s forever loop fires every frame and the host stutters. That is the interesting mistake, and it is worth letting them make it. The fix is to warn where the life is LOST — in the else branch, right after the change block — because that only happens once.
Three endings
Pass and fail is not enough. Add a third ending for a perfect score.
- A perfect score gets its own message.
- A pass gets the ordinary one.
- Everything else gets the try-again one.
- Nobody ever sees two endings at once.
Teacher note — an if inside an else
The shape is one if / else with a second if / else inside its else half. Test from the highest score downwards, or everybody gets the bottom ending.
if <(score) > [3]> then
say [Perfect score!] for (4) seconds
else
if <(score) > [1]> then
say [You pass.] for (4) seconds
else
say [Try again!] for (4) seconds
end
end
The nesting is the hard part, not the numbers. Get them to drag the inner if / else in last, once the outer one already works.
Higher or Lower
Add a bonus round. The host thinks of a number between 1 and 20, and you get six guesses. After every guess the host says Higher! or Lower!
How to use this: Click the green flag, then type your answer in the box and press Enter.
- The number is different every time you play.
- Every guess gets a clue: higher, lower, or you got it.
- A correct guess ends the round straight away.
- Running out of guesses ends it too, and says what the number was.
Teacher notes — three comparisons on one number
when flag clicked
set [secret v] to (pick random (1) to (20))
repeat (6)
ask [Guess my number, 1 to 20] and wait
if <(answer) > (secret)> then
say [Lower!] for (1) seconds
end
if <(answer) < (secret)> then
say [Higher!] for (1) seconds
end
if <(answer) = (secret)> then
say [You got it!] for (2) seconds
stop [this script v]
end
end
say (join [Out of guesses. It was ] (secret)) for (3) seconds
Three ifs rather than one if / else, because there are three outcomes and exactly one of them is true each time. The repeat (6) is what stops it asking for ever, and the say block under the loop only ever runs when the player has failed — a stop-this-script above it has already taken the winner away.
Going further: next lesson every question gets its own card, its own sound and its own number of points.
Summary 4 min
A quiz you cannot fail is not a quiz. Today yours grew teeth.
- A wrong answer takes a life, in the else branch you already had.
- The lives check goes between marking the answer and asking the next question.
stop [this script v]ends one stack. Everything else keeps running.<() > ()>turns a score into a pass or a fail.
- Lives
- How many mistakes the player is allowed before the game ends.
- Greater than
- Asks whether the left number is bigger than the right one. Exactly equal is not bigger.
- Stop this script
- Ends the stack it sits in. Other stacks carry on.
- Pass mark
- The score you decide is good enough. It is a number you choose, not a rule.
Next lesson: a card behind every round, a sound for right and wrong, and a hard question worth three points.