- Learnt28 min · insert in order, packs as codes, a front door, a cold test
- Basic25 min · the finished quiz
- Challenge 1–327 min · read the table, your rank, refuse a bad pack
- Extrabonus · a pack menu
Review — Quiz Engine III 5 min
playersandscoreswere two lists in step;turnwas the row playing.modwrapped the turn back to 1 after the last player.- A question timer was the timer now, take away the timer when it was asked.
- The winner was found in two passes, so a tie could not hide.
Quick-fire
In Tile Maker, how did a whole level get from one project to another?
Reveal the answer
As a save code — all twelve rows joined into one long line of letters, typed into an ask, and cut back into rows. Today a question pack travels the same way.
Today’s Topic 3 min
- A top five in two lists, kept in order with
insert (thing) at (place) of [list v] - A table the green flag never clears
- A question pack as one code, cut apart by
splitwith a second input - A front door — and a cold test with a real player
Learning outcome
By the end of this lesson you will be able to:
- Keep a list sorted by inserting each new item in its place.
- Pack a whole list into one piece of text, and unpack it.
- Finish a game so a stranger can pick it up and play.
Learnt — a quiz that lasts 28 min
1 · Insert in order
Card Battle sorted a whole list with bubble sort. A top five never needs that, because it is already in order. A new score just needs its place: walk down the table until it beats the score there, and insert it.
define add to top five (name) (points)
set [place v] to (1)
repeat until <<(place) > (length of [top scores v])> or <(points) > (item (place) of [top scores v])>>
change [place v] by (1)
end
insert (name) at (place) of [top names v]
insert (points) at (place) of [top scores v]
if <(length of [top scores v]) > (5)> then
delete (6) of [top names v]
delete (6) of [top scores v]
end
How to use this: Click the green flag to start it. Nothing else to press — eight scores arrive one at a time. Watch both lists.
How to use this: Click the green flag to start it. Nothing else to press. This one uses the “beats or equals” test.
2 · The table survives the green flag
Look at what the green flag does not do: it never deletes the top lists. Each new game sets score to 0 but leaves the table alone — the same trick as Kart Racer’s best lap.
How to use this: Click the green flag to start it. Nothing else to press — a script plays two games that score 6 and 8. Then press the flag again.
The table lasts as long as the project is open, and is saved with it. Reload the page and it goes back to whatever the project was saved with.
3 · A question pack in one code
A bank is a list of lines. Join them with ~ between, and the whole bank is one piece of text — a pack you can copy, send to a friend and paste in.
How to use this: Click the green flag to start it. Nothing else to press.
To load a pack, cut it at every ~. That is exactly what split does — except it always cuts at |. Give it a second input, cut, that says where to cut.
define split (text) (cut)
delete all of [parts v]
set [word v] to []
set [i v] to (1)
repeat (length of (text))
set [letter v] to (letter (i) of (text))
if <(letter) = (cut)> then
add (word) to [parts v]
set [word v] to []
else
set [word v] to (join (word) (letter))
end
change [i v] by (1)
end
add (word) to [parts v]
split (item (q) of [bank v]) [|] :: custom.
split (code) [~] :: custom
delete all of [bank v]
set [k v] to (1)
repeat (length of [parts v])
add (item (k) of [parts v]) to [bank v]
change [k v] by (1)
end
How to use this: Click the green flag to start it. Nothing else to press — a Space pack is loaded from one code.
4 · A front door
A stranger opening your project needs to know what it is and how to start. A title, a how-to-play card and a Play button, all hidden when the game begins.
How to use this: Click the green flag, then click the Play button when it appears.
5 · The cold test
Give your quiz to someone who has never seen it. Say nothing. Watch, and write down every moment they hesitate or ask you something. Each one is a job for you: a clearer card, a better message, a guard on what they type.
Basic — the finished quiz 25 min
Open your quiz. This is where it all comes together.
Step 1 — the top five
- Make the lists
top namesandtop scores, and the variableplace. Type three made-up names and scores in to start the table. - Make the
add to top fiveMy Block from Learnt section 1. - After the quiz loop: if the table has fewer than 5 rows or the score beats row 5, ask for a name and add it.
if <<(length of [top scores v]) < (5)> or <(score) > (item (5) of [top scores v])>> then
ask (join [You scored ] (join (score) [ - that's in the top five! Your name?])) and wait
add to top five (answer) (score) :: custom
else
say (join [You scored ] (join (score) [. Not quite the top five - try again!]))
end
Step 2 — the front door
- Save our title.svg and play.svg, and upload them as two sprites.
- The Play sprite:
when this sprite clicked, hide,broadcast (play v). - Move the quiz from under the green flag to
when I receive [play v]. The title hides when it receivesplaytoo.
How to use this: Click the green flag, then click Play. Type 1, 2 or 3 and press Enter; type your name if you make the table.
The name goes in, but the score is in the wrong row.
The two insert blocks use different places, or one is add instead of insert. Both must say (place).
The table is empty every game.
There is a delete all of [top scores v] under the green flag. Take it out — that is the whole point.
Nothing happens when I click Play.
The quiz is still under when flag clicked, or the message names do not match.
Read the table out
List monitors are fine for you; a player wants a proper table.
- Kiran says the whole table in one line: place, name, score.
- Hide the two list monitors.
How to use this: Click the green flag to start it. Nothing else to press.
Teacher reveal
set [line v] to []
set [k v] to (1)
repeat (length of [top scores v])
set [line v] to (join (line) (join (k) (join [. ] (join (item (k) of [top names v]) (join [ ] (join (item (k) of [top scores v]) [ ]))))))
change [k v] by (1)
end
say (line)
Your rank
Tell the player exactly where they came.
- After the insert, say “You came 2nd!” — or 1st, 3rd, 4th, 5th.
- The words come from a list, not from five
ifblocks.
How to use this: Click the green flag to start it. Nothing else to press — Jo’s 8 is added to a full table.
Teacher reveal
place already holds the rank — it is where the insert went. Make a list places holding 1st 2nd 3rd 4th 5th, then:
add to top five [Jo] (8) :: custom
say (join [Jo, you came ] (join (item (place) of [places v]) [!]))
Refuse a bad pack
A friend’s pack might have a typo. Check it before it replaces your bank.
- After loading, cut every line at | and count its parts.
- If any line does not make 5, empty the bank and say which line was bad.
- This is Lesson 37’s bank checker, now with a second input.
How to use this: Click the green flag to start it. Nothing else to press — the pack has a broken second line.
Teacher reveal
set [bad v] to (0)
set [q v] to (1)
repeat (length of [bank v])
split (item (q) of [bank v]) [|] :: custom
if <<not <(length of [parts v]) = (5)>> and <(bad) = (0)>> then
set [bad v] to (q)
set [bad parts v] to (length of [parts v])
end
change [q v] by (1)
end
if <(bad) = (0)> then
say (join [Pack loaded: ] (join (length of [bank v]) [ questions.]))
else
delete all of [bank v]
say (join [Bad pack: line ] (join (bad) (join [ has ] (join (bad parts) [ parts. Nothing loaded.]))))
end
A pack menu
One project, many quizzes.
- Keep three packs in a
packslist, one code per row, and their names inpack names. - Ask which pack to play, load it, and play it.
- Say the pack’s name with the score at the end.
How to use this: Click the green flag, type 1, 2 or 3 to choose a pack, then answer its questions.
Summary 5 min
- An ordered table stays ordered if every new item is inserted at its place.
- A score that beats goes above; one that only equals goes below.
- Anything the green flag does not reset survives every new game.
- A pack is lines joined with ~.
splitwith a second input cuts it apart again. - A finished game has a front door, and has been played cold by someone else.
- Insert
- Putting an item into a list at a place, pushing the rest down.
- Pack
- A whole question bank written as one piece of text.
- Cold test
- Watching someone play your game for the first time, without helping.
Hand in
Save your finished Quiz Engine, and write down three things from your cold test. Keep it — every quiz you make from now on can run on this engine.