- Learnt28 min · a streak, a level, a mix of × and +
- Basic25 min · build all three into your game
- Challenge 1–327 min · streak shouts, a medium level, take-away
- Extrabonus · hard is worth double
Review — where we got to 5 min
reset timerstarts the clock.(round ((60) - (timer)))shows the time left.repeat until <<(timer) > (60)> or <(lives) = (0)>>ends the round by itself.- The clock has its own script, so it ticks while you type.
Quick-fire
Right now every right answer is worth 1 point. Ten right in a row is 10 points. Is that fair to someone who never slipped?
Reveal the answer
Many games say no. They reward a streak — right answers in a row. That is today’s first idea.
Today’s Topic 3 min
- A
streakvariable, andchange [score v] by (streak) - A level chosen first, kept in
minandmax - A coin toss with
<(pick random (1) to (2)) = [1]>for × or + broadcast [new question v] and wait— one script makes the question
Learning outcome
By the end of this lesson you will be able to:
- Keep a streak that grows, and resets to 0 on a mistake.
- Ask for a level first, and use it in every question.
- Mix two kinds of question, with the right answer kept in one place.
Learnt — streak, level, mix 28 min
1 · A streak
A streak counts right answers in a row. One wrong answer sends it back to 0.
Now make each right answer worth the streak. Watch the points grow:
| Answer | streak | Points | score |
|---|---|---|---|
| right | 1 | +1 | 1 |
| right | 2 | +2 | 3 |
| right | 3 | +3 | 6 |
| wrong | 0 | +0 | 6 |
| right | 1 | +1 | 7 |
In blocks it is four lines inside the if / else you already have:
if <(answer) = (correct)> then
change [streak v] by (1)
change [score v] by (streak)
else
set [streak v] to (0)
change [lives v] by (-1)
end
(streak) goes in the round hole of the change block. The score goes up by whatever the streak is now.A practice Robot shows it best. It answers by itself, and it is right about three times in four:
when flag clicked
set [score v] to (0)
set [streak v] to (0)
repeat (12)
if <(pick random (1) to (4)) > (1)> then
say [Right!] for (1) seconds
change [streak v] by (1)
change [score v] by (streak)
else
say [Wrong!] for (1) seconds
set [streak v] to (0)
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.
Three kinds of variable
| Variable | Set to its start value… |
|---|---|
score, lives | once, at the start of each round |
streak | at the start of each round, AND on every mistake |
a, b | on every question |
2 · Choose a level first
A six-year-old and a twelve-year-old should not get the same questions. Ask first, and keep the answer in two numbers: the smallest and the biggest allowed.
- Make two variables,
minandmax. - At the top of the flag script, add
ask [Easy or hard?] and wait. - Add an if / else with
<(answer) = [hard]>. - Hard sets min to 2 and max to 12. Easy sets 1 and 5.
- In both set blocks for a and b, drop
(min)and(max)into pick random.
when flag clicked
ask [Easy or hard?] and wait
if <(answer) = [hard]> then
set [min v] to (2)
set [max v] to (12)
else
set [min v] to (1)
set [max v] to (5)
end
repeat (3)
set [a v] to (pick random (min) to (max))
set [b v] to (pick random (min) to (max))
say (join (a) (join [ × ] (b))) for (2) seconds
end
How to use this: Click the green flag, then type easy or hard in the box and press Enter.
3 · A mix of × and +
Let the program toss a coin. (pick random (1) to (2)) gives 1 or 2, like heads or tails. 1 means a times question. 2 means a plus question.
Here is the smart part. Work out the right answer in the same place you build the question. Keep it in a variable called correct.
when I receive [new question v]
set [a v] to (pick random (1) to (10))
set [b v] to (pick random (1) to (10))
if <(pick random (1) to (2)) = [1]> then
set [question v] to (join (a) (join [ × ] (b)))
set [correct v] to ((a) * (b))
else
set [question v] to (join (a) (join [ + ] (b)))
set [correct v] to ((a) + (b))
end
Now the round needs just one check, whatever the sign:
broadcast [new question v] and wait
ask (question) and wait
if <(answer) = (correct)> then
end
broadcast [new question v] and wait waits until the question is ready. A plain broadcast would ask before it was made.
when flag clicked
repeat (6)
broadcast [new question v] and wait
say (join (question) (join [ = ] (correct))) for (2) seconds
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.
Basic — streak, level and mix in your game 25 min
Open your sixty-second game. You will end with four scripts on the Wizard.
Step 1 — five new variables
- Make
streak,min,max,questionandcorrect. - Leave streak ticked. Untick the others.
Step 2 — the question maker
- Build the
when I receive [new question v]script from Learnt 3. - Use
(min)and(max)in both pick random blocks.
Step 3 — split the flag script
- Pull everything from
reset timerdown off the flag script. - Put
when I receive [play v]on top of it. - The flag script now asks the level, sets score, streak and lives, then broadcasts
play.
Step 4 — the new round
- Inside the loop, replace the two set blocks with
broadcast [new question v] and wait. - Ask
(question). Check against(correct). - Add the streak blocks to both halves of the if / else.
Step 5 — play it three ways
- Play on easy. Get five right in a row. Watch score jump.
- Play on hard. Check no number is below 2 or above 12.
- Get one wrong on purpose. Check streak goes to 0.
when flag clicked
ask [Easy or hard?] and wait
if <(answer) = [hard]> then
set [min v] to (2)
set [max v] to (12)
else
set [min v] to (1)
set [max v] to (5)
end
set [score v] to (0)
set [streak v] to (0)
set [lives v] to (3)
broadcast [play v]
when I receive [play v]
reset timer
broadcast [clock v]
repeat until <<(timer) > (60)> or <(lives) = (0)>>
broadcast [new question v] and wait
ask (question) and wait
if <(answer) = (correct)> then
change [streak v] by (1)
change [score v] by (streak)
else
set [streak v] to (0)
change [lives v] by (-1)
say (join [It is ] (correct)) for (1) seconds
end
end
say (join [Round over! Score: ] (score)) for (4) seconds
The question maker is the one in Learnt 3, with (min) and (max) in the pick random blocks. The clock is last lesson’s, unchanged.
How to use this: Click the green flag, then type easy or hard and press Enter. Then type your answer in the box and press Enter for each question.
Hard still gives small numbers.
Your pick random blocks still say 1 and 10. Drop (min) and (max) into them.
The Wizard asks an empty question.
You used broadcast [new question v] without “and wait”. The round asked before the question was made.
streak never goes back to 0.
The else half needs set [streak v] to (0).
Every right answer is worth only 1.
Check the change block says (streak), not 1. And check the streak grows before the score does.
Shout the streak
Make the Wizard cheer when a streak gets going.
- At a streak of 3, he says “3 in a row!”.
- At a streak of 5, he says “5 in a row! On fire!”.
- Other right answers get no cheer.
Teacher reveal
change [streak v] by (1)
change [score v] by (streak)
if <(streak) = (3)> then
say [3 in a row!] for (1) seconds
end
if <(streak) = (5)> then
say [5 in a row! On fire!] for (1) seconds
end
Both ifs go in the top half, after the streak has grown.
A medium level
Add a level between easy and hard.
- The question becomes “Easy, medium or hard?”.
- Medium uses numbers from 2 to 9.
- Easy and hard still work as before.
Teacher reveal — an if inside the else
ask [Easy, medium or hard?] and wait
if <(answer) = [hard]> then
set [min v] to (2)
set [max v] to (12)
else
if <(answer) = [medium]> then
set [min v] to (2)
set [max v] to (9)
else
set [min v] to (1)
set [max v] to (5)
end
end
Easy stays in the last else, so anything unexpected still lands somewhere safe.
Take-away, never below zero
Add a third kind of question: take-away. The answer must never be below zero.
- About one question in three is a take-away.
- The big number always comes first.
- The check still uses correct, so the round does not change.
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.
Teacher reveal — build it backwards
Pick the answer and the small number first. Add them to make the big number. Then ask big − small, and the answer is always the one you picked.
when flag clicked
repeat (6)
set [a v] to (pick random (1) to (10))
set [b v] to (pick random (1) to (10))
set [big v] to ((a) + (b))
say (join (big) (join [ - ] (join (b) (join [ = ] (a))))) for (2) seconds
end
That is the demo. In the question maker it becomes:
set [big v] to ((a) + (b))
set [question v] to (join (big) (join [ - ] (b)))
set [correct v] to (a)
The coin becomes (pick random (1) to (3)), with an if inside the else for the third kind. Some pupils swap a and b with an if instead. That works too, and needs a spare variable — let them find out why.
Hard is worth double
A streak on hard should be worth more than the same streak on easy.
- On hard, each right answer scores the streak times 2.
- On easy, it scores the streak, as now.
- The end of the round also says your best streak.
Teacher reveal
if <(answer) = (correct)> then
change [streak v] by (1)
change [score v] by ((streak) * (bonus))
if <(streak) > (best streak)> then
set [best streak v] to (streak)
end
else
set [streak v] to (0)
change [lives v] by (-1)
end
bonus is set beside min and max: 2 for hard, 1 for easy. best streak is set to 0 at the start of each round. It is a round best, not an all-time best — that is next lesson.
Summary 4 min
Today the round got deeper without getting longer.
- A
streakgrows on a right answer and goes to 0 on a wrong one. change [score v] by (streak)makes long streaks pay.- A level chosen first sets
minandmaxfor every question. - The question maker builds the question and
correcttogether, so the round has one check.
- Streak
- How many right answers in a row, since the last mistake.
- Level
- How hard the game is. Here, how big the numbers are.
- Coin toss
- A pick random between 1 and 2. Each has an even chance.
- And wait
- Makes a broadcast wait until every script it started has finished.
Next lesson: the last of the arc. A menu with buttons, a best score that is never wiped, and a results card in words.