复习 — 我们学到哪里了 5 分钟
上星期,你做了一个有三道题和得分的问答秀。今天会再用到它的两种积木。
ask [] and wait,还有它保存下来的(answer)。if <> then和它的else下半部分,菱形格里放着<() = ()>。
快问快答
就算玩家答得很差,你的问答秀还是会把三道题都问完。怎样才能让它提前结束?
看答案
要有一样会输掉的东西,还要有一个看着它什么时候用完的东西。这两样你在接东西游戏里都做过。它们就是 lives 变量,和一个检查它的脚本。
今天的主题 3 分钟
- 一个
lives变量。答错一题,就少一条命。 - 一个只看着生命值的脚本。
stop [this script v]。它只停一组积木,不是停整个问答秀。<() > ()>。它让你可以定一个及格分数。
学习目标
学完这一课,你能够:
- 玩家答错时,减掉一条命。
- 命一用完,就结束问答秀。
- 说出玩家有没有及格。及格分数由你来定。
学一学 — 生命值、裁判、及格分数 28 分钟
1 · 答错一题,少一条命
你已经有 else 分支了。玩家每次答错,它就会运行。在里面再放一块积木。
- 在 Variables(变量)里,做一个叫
lives的变量。 - 在绿旗那组积木里,加上
set [lives v] to (3)。 - 在题目的 else 分支里,加上
change [lives v] by (-1)。 - 运行它,故意答错。看舞台上的数字变小。
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
怎么用: 点绿旗,然后在框里输入你的答案,按 Enter。
2 · 总得有人注意到
现在生命值可以变成 0 了。可是变成 0 时,什么也没发生。问答秀需要一个裁判。裁判就是一个只负责看着的脚本。
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
怎么用: 点绿旗开始。不用再按别的,看它演完,然后用 ↺ Reset 再运行一次。
3 · 一道题里面的顺序
把裁判放在一直重复的循环(forever)里,是可以的。但它可能会慢一点点。下一道题可能已经出现在屏幕上了。更整齐的办法,是在题目脚本里面检查。
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 · 及格了吗?
4 题答对 3 题,算及格。只对 1 题,就不及格。要分辨它们,你需要问一个新问题:一个数是不是比另一个数大?
- 打开 Operators(运算)。
- 找到
<() > ()>。它就在等于积木的上面。 - 把
(score)拖到左边。 - 在右边输入你的及格分数。
- 把整块放进 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
怎么用: 点绿旗,然后在框里输入你的答案,按 Enter。
基础任务 — 四道题,三条命 25 分钟
从上星期的作品开始。你是在它上面加东西,不是重新开始。
第 1 步 — 变量
- 做一个叫
lives的变量。让它显示着。 - 把
set [lives v] to (3)加到绿旗那组积木里。放在设定 score 的积木下面。
第 2 步 — 一次改一道题
- 打开你的 question 1 脚本。
- 把普通的
if <> then换成if / else。 - 把
change [lives v] by (-1)放进 else 下半部分。 - 试一试。故意答错。看生命值掉到 2。
第 3 步 — 其他题也一样
- 第 2、3、4 题也这样做。
- 每改好一道,就试一试。
第 4 步 — 出局检查
- 在第 1 题的 if / else 下面,加上
if <(lives) = [0]> then。 - 在它里面放
broadcast [out v]和stop [this script v]。 - 把这块 if 积木复制到第 2 题和第 3 题里。
- 做
when I receive [out v]脚本。先用一块 say 积木,然后用stop [all v]。
第 5 步 — 及格分数
- 打开你的
when I receive [result v]脚本。 - 把它里面的积木放进一个 if / else 里。这个 if / else 检查得分。
- 自己定一个及格分数,把它输入进去。
第 6 步 — 用三种方法玩
- 全部答对。你应该及格。
- 全部答错。答错三道以后,问答秀应该结束。
- 刚好得到你的及格分数。检查结局是不是你想要的那个。
问答秀结束了,却还在继续提问。
少了 stop [this script v]。或者它放在广播的下面,而不是上面。
我从来没看到“Out of lives”这句话。
say 积木还没说完,stop [all v] 就运行了。用 say [] for (3) seconds,然后再停。
我第二次玩,一开始就没有命了。
设定为 3 的积木放错了那组积木。它要放在绿旗下面,最开始的地方。
刚好得到及格分数,却不及格。
<() > ()> 就是这样的。你想让刚好这个分数也及格吗?那就把数字改小 1。
一错就出局
做一个有六道题、只有一条命的版本。
- 六道题。
- 一条命。
- 答错一题,问答秀马上结束。
提醒玩家
玩家应该知道快结束了。玩家只剩最后一条命时,让主持人说一句话。
- 生命值变成 1 时才提醒,不能更早。
- 只提醒一次,不是一遍又一遍。
- 如果玩家一题都没答错,就完全不提醒。
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.
三种结局
只有及格和不及格还不够。为满分加第三种结局。
- 满分有自己的一句话。
- 及格的得到平常那句。
- 其他的都得到“再试一次”那句。
- 谁也不会同时看到两种结局。
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.
猜大猜小
加一个奖励回合。主持人想一个 1 到 20 之间的数。你有六次机会猜。每猜一次,主持人都会说 Higher!(大一点!)或 Lower!(小一点!)
怎么用: 点绿旗,然后在框里输入你的答案,按 Enter。
- 每次玩,数字都不一样。
- 每猜一次都有提示:大一点、小一点,或者猜中了。
- 猜对了,这一轮马上结束。
- 机会用完了,这一轮也会结束。然后它会说出那个数是多少。
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.
总结 4 分钟
不会不及格的问答,不算真的问答。今天你的问答秀变难了。
- 答错一题就少一条命。这是在你本来就有的 else 分支里做的。
- 先判分。再看生命值。然后问下一题。
stop [this script v]只结束一组积木。其他的都继续运行。<() > ()>把得分变成及格或不及格。
- 生命值
- 游戏结束前,玩家可以犯几次错。
- 大于
- 检查左边的数是不是比右边的大。一样的数不算大。
- stop this script(停止这个脚本)
- 结束它所在的那组积木。其他积木继续运行。
- 及格分数
- 你认为够好的分数。数字由你来定。
下一课:每一轮后面都有一张卡片,答对答错都有声音。难题值三分。