- Learnt28 min · players and scores, turns with mod, a timer, a winner
- Basic25 min · a three-player quiz
- Challenge 1–327 min · a score line, rounds, a speed bonus
- Extrabonus · sudden death
Review — Quiz Engine II 5 min
- Random picks repeat. Deleting as you go empties the bank.
- Fisher-Yates swapped each place, from the bottom up, with one at or above it.
- A swap needed
temp. Without it, one number was copied and another lost. - The answers were shuffled too, and
item # offound the right one.
Quick-fire
Kart Racer’s Gate counted next gate up to 4, then back to 1. Which block did that?
Reveal the answer
An if: “if next gate > length of gate x, set it to 1”. Today the same wrap is done in one line, with mod.
Today’s Topic 3 min
- Two lists in step:
playersandscores - A
turnthat wraps:(((turn) mod (length of [players v])) + (1)) - A pass-it-on card, and a timer for each question
- A winner, and a tie when two players share the best score
Learning outcome
By the end of this lesson you will be able to:
- Keep one number per player in a list and change the right one.
- Take turns round any number of players.
- Find the best score and every player who has it.
Learnt — a quiz for the whole room 28 min
1 · Whose turn?
The names go in a list called players. turn is a row number: (item (turn) of [players v]) is whoever is playing. After each turn it moves on by one — and after the last player, it wraps back to 1.
set [turn v] to (1)
repeat (10)
say (join (item (turn) of [players v]) ['s turn]) for (0.6) seconds
set [turn v] to (((turn) mod (length of [players v])) + (1))
end
mod is the remainder: 4 mod 4 is 0, so after player 4 comes 0 + 1 = 1.How to use this: Click the green flag to start it. Nothing else to press — ten turns for four players.
How to use this: Click the green flag to start it. Nothing else to press. This one uses change turn by 1, with no wrap.
2 · Scores in step, and passing the laptop
A second list, scores, has one row per player. Row turn of it is the score of whoever is playing, so a point goes there:
replace item (turn) of [scores v] with ((item (turn) of [scores v]) + (1))
Before each question, a Pass card says it is time to hand the laptop on. The question waits until the next player presses space.
broadcast (pass v) and wait
say (join (item (turn) of [players v]) [, press space when you have the laptop.])
wait until <key (space v) pressed?>
when I receive [pass v], show, wait 0.5 seconds, hide.How to use this: Click the green flag to start it. Nothing else to press — a script plays six turns for three players, with the card between them.
3 · A timer for each question
Write down the timer when the question appears. When the answer comes back, take it away. Too slow scores nothing.
set [asked at v] to (timer)
ask (question) and wait
set [took v] to (([round v] of (((timer) - (asked at)) * (10))) / (10))
if <(took) > (5)> then
say (join [Too slow! ] (join (took) [ s])) for (0.6) seconds
else
// check the answer, as before
end
How to use this: Click the green flag to start it. Nothing else to press — a script answers three questions right, one of them slowly.
4 · The winner — or a tie
Two passes through the scores. The first finds the best score. The second collects every player who has it into a winners list.
set [best v] to (item (1) of [scores v])
set [k v] to (1)
repeat (length of [scores v])
if <(item (k) of [scores v]) > (best)> then
set [best v] to (item (k) of [scores v])
end
change [k v] by (1)
end
delete all of [winners v]
set [k v] to (1)
repeat (length of [scores v])
if <(item (k) of [scores v]) = (best)> then
add (item (k) of [players v]) to [winners v]
end
change [k v] by (1)
end
winners is a win. Two or more is a tie.How to use this: Click the green flag to start it. Nothing else to press — the scores are 3, 5, 2 and 4.
How to use this: Click the green flag to start it. Nothing else to press — the scores are 3, 5, 2 and 5.
Basic — a three-player quiz 25 min
Open your quiz from Quiz Engine II. You can keep the shuffles in.
Step 1 — the players
- Make two lists,
playersandscores, and type three names intoplayers. - Make a
winnerslist and the variablesturn,bestandk. - Under the green flag:
delete all of [scores v], thenrepeat (length of [players v])withadd (0) to [scores v]inside.
Step 2 — the Pass card
- Save our card, pass-card.svg, and use Upload Sprite. Call it
Pass card. - Give it the receive script from Learnt section 2.
Step 3 — turns
- In the quiz loop, before the split: the three pass blocks from section 2.
- A right answer replaces the player’s row in
scores, instead of changingscore. - At the end of the loop, move the turn on with mod.
- After the loop, find the winners, then say the winner or the tie.
How to use this: Click the green flag, then click the stage once. Press space to take the laptop, then type 1, 2 or 3 and press Enter.
Every point goes to the first player.
The replace says 1 where it should say turn, in both places.
The game asks the same player twice.
The mod line is inside the if for a right answer, so the turn only moves on after a right answer. Put it at the end of the loop.
Pressing space does nothing.
Click the Stage first, so Scratch is listening to the keyboard.
A score line
Everybody wants to know the scores.
- After every turn, Kiran says every player’s name and score in one line.
- The line is built by a loop, so it works for 2, 3 or 4 players.
- A dot goes between players, but not after the last one.
How to use this: Click the green flag to start it. Nothing else to press — a script plays six turns.
Teacher reveal
set [line v] to []
set [k v] to (1)
repeat (length of [players v])
set [line v] to (join (line) (join (item (k) of [players v]) (join [ ] (item (k) of [scores v]))))
if <(k) < (length of [players v])> then
set [line v] to (join (line) [ · ])
end
change [k v] by (1)
end
say (line) for (0.9) seconds
Rounds
Fair games give everyone the same number of questions.
- A
roundsvariable: how many questions each player gets. - The game plays exactly rounds × players turns, then ends itself.
- Then it names the winner.
How to use this: Click the green flag to start it. Nothing else to press — a script plays three rounds for three players.
rounds or adding a player changes the length of the game, with no other change.Teacher reveal
Replace the loop’s count with repeat ((rounds) * (length of [players v])). The bank needs at least that many lines — or deal from it with q wrapping round, the same mod trick as the turn.
A speed bonus
Reward the quick thinkers.
- A right answer in under 2 seconds scores 2.
- A right answer that is slower scores 1.
- A wrong answer scores 0, however fast.
How to use this: Click the green flag to start it. Nothing else to press — a script answers six questions at different speeds.
Teacher reveal
if <(item ((pick) + (1)) of [parts v]) = (item (5) of [parts v])> then
if <(took) < (2)> then
replace item (turn) of [scores v] with ((item (turn) of [scores v]) + (2))
else
replace item (turn) of [scores v] with ((item (turn) of [scores v]) + (1))
end
end
Sudden death
A tie is fair, but a room full of players usually wants a winner.
- If two players tie, they get one extra question each.
- If one is right and the other is not, the right one wins.
- If they are both right or both wrong, go again.
How to use this: Click the green flag to start it. Nothing else to press — Alex and Max start on 5 each, and a script answers for them.
Summary 5 min
playersandscoresare two lists in step.turnis the row playing.((turn) mod (players)) + 1goes round any number of players.- A question timer is the timer now, take away the timer when it was asked.
- Find the best score first, then every player with it. More than one is a tie.
- Turn
- Whose go it is — here, a row number in the players list.
- Mod
- The remainder after dividing. It makes a count go round in a circle.
- Tie
- Two or more players sharing the best score.
Hand in
Save your pass-and-play quiz. Next lesson it remembers the best players even after the game is over, and loads whole question packs from a single code.