- 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 of its blocks come back today.
ask [] and wait, and the(answer)it keeps.if <> thenand itselsehalf, with<() = ()>in the diamond.
Quick-fire
Your quiz asks all three questions, even when the player does badly. What would make it stop early?
Reveal the answer
Something to lose, and something that watches for it to run out. You built both in the catching game. They were a lives variable and a script that checks it.
Today’s Topic 3 min
- A
livesvariable. A wrong answer takes one away. - A script that only watches the lives.
stop [this script v]. It stops one stack, not the whole show.<() > ()>. This gives you 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 as soon as the lives run out.
- Say if the player passed. You choose the pass mark.
Learnt — lives, the referee, the pass mark 28 min
1 · A wrong answer costs a life
You already have the else branch. It runs each 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 give wrong answers. 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. But nothing happens when they do. The show needs a referee. This is one script that only watches.
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. A tidier way is to check inside 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. 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 add to it. You do not start again.
Step 1 — the variable
- Make a variable called
lives. Leave it showing. - Add
set [lives v] to (3)to the green-flag stack. Put it 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. Use a say block, thenstop [all v].
Step 5 — the pass mark
- Open your
when I receive [result v]script. - Put what is in it inside an if / else. The if / else 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 wrong.
- Get exactly your pass mark. Check that the ending is the one you wanted.
The show ends but keeps asking questions.
stop [this script v] is missing. Or it sits under the broadcast, not above it.
I never see the “Out of lives” message.
stop [all v] runs 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 goes on the green flag, at the very start.
A score exactly on the pass mark fails.
That is what <() > ()> does. Do you want the mark itself to pass? Then make the number one lower.
Sudden death
Make a version with six questions and only one life.
- Six questions.
- One life.
- One wrong answer ends the show straight away.
Warn them
A player should know the end is near. Make the host say something when they are down to their last life.
- The warning shows when lives reach 1, not before.
- It shows once, not over and over.
- It does not show at all if they get nothing 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 are not enough. Add a third ending for a perfect score.
- A perfect score gets its own message.
- A pass gets the normal 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 from 1 to 20. 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. Then it 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 real quiz. Today yours got harder.
- A wrong answer takes a life. This happens in the else branch you already had.
- First mark the answer. Then check the lives. Then ask 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 can make before the game ends.
- Greater than
- Checks if the left number is bigger than the right one. The same number is not bigger.
- Stop this script
- Ends the stack it sits in. Other stacks carry on.
- Pass mark
- The score that you decide is good enough. You choose the number.
Next lesson: a card behind every round and a sound for right and wrong. A hard question is worth three points.