复习:我们学到哪里了 5 分钟
- 故事地图画出每个场景和每个岔路口。
- 按钮是一个角色。
when this sprite clicked加上一个 broadcast,就是一个选择。 - 每个按钮收到每条路的消息都会藏起来。
快问快答
你点了 The Lake。The Lake 按钮藏起来了。可是 The Woods 按钮还留在屏幕上。少了什么?
看答案
The Woods 按钮没有 when I receive [go lake v] + hide。它只在收到自己的消息时才藏起来。
今天的主题 3 分钟
- 一个会记住事情的变量:
(has key)。 - 一扇会检查它的门。
- 同时检查两件事:
<<> and <>>。 ask [What is your name?] and wait、(answer)和(join [Hello, ] (name))。
学习目标
上完这节课,你能够:
- 用一个变量记住读故事的人做了什么。
- 让故事用 if / else 和 and 来检查它。
- 只问一次读故事的人的名字,再把它放进故事的台词里。
学一学:会记住事情的故事 28 分钟
故事会忘记
现在,你在树林里做了什么,后面都不重要。城堡的门没法知道树林里发生了什么。变量可以把它记住。
- 打开 Variables(变量),点 Make a Variable(新建一个变量)。
- 把它叫做 has key。保留 For all sprites(适用于所有角色)。
- 勾上它的方框,这样你就能在舞台上看到它。
捡起钥匙
添加 Key 角色。它放在树林里。点一下就能捡起来。
when backdrop switches to [Forest v]
hide
when backdrop switches to [Woods v]
show
when backdrop switches to [Castle 1 v]
hide
when this sprite clicked
set [has key v] to [yes]
hide
读故事的人需要时间来选。所以树林这条路会停下来,等一个 Walk On(继续走)按钮。这里没有计时器,所以不用急。
when I receive [go woods v]
switch backdrop to [Woods v]
broadcast [woods scene v] and wait
broadcast [walk on v]
when flag clicked
hide
when I receive [walk on v]
show
when this sprite clicked
broadcast [go door v]
when I receive [go door v]
hide
门会检查
到了门口,故事会读这个变量,然后走这条路或那条路:
when I receive [go door v]
switch backdrop to [Castle 1 v]
if <(has key) = [yes]> then
say [The key fits! The door opens.] for (2.5) seconds
switch backdrop to [Castle 3 v]
else
say [The door is locked.] for (2.5) seconds
end
Wizard 还要在最开始、去树林之前,用 set [has key v] to [no] 设好变量。
怎么用: 点绿旗。如果你想让 Gobo 拿钥匙,就点钥匙,然后点 Walk On。
同时检查两件事:and
森林里有一个苹果。门后面的 Dragon 很饿。再做一个变量,叫 has apple。苹果被点的时候就设好它。
<<> and <>> 在 Operators(运算)里。只有两边都成立,它才成立。
| has key | has apple | 会发生什么 |
|---|---|---|
| yes | yes | Dragon 吃掉苹果。现在它是 Gobo 的朋友了。 |
| yes | no | 门打开了。可是 Dragon 太饿了,不想玩。 |
| no | yes 或 no | 门是锁着的。 |
if <<(has key) = [yes]> and <(has apple) = [yes]>> then
switch backdrop to [Castle 3 v]
broadcast [friend ending v] and wait
else
if <(has key) = [yes]> then
switch backdrop to [Castle 3 v]
broadcast [hungry ending v] and wait
else
broadcast [locked ending v] and wait
end
end
say [The end!] for (2) seconds
怎么用: 点绿旗。点钥匙、点苹果、两个都点,或者都不点,然后点 Walk On。
故事里有你的名字
| 积木 | 类别 | 它做什么 |
|---|---|---|
ask [What is your name?] and wait | Sensing | 显示问题和一个输入框。一直等到读故事的人按 Enter。 |
(answer) | Sensing | 读故事的人上一次输入的内容。 |
(join [Hello, ] (name)) | Operators | 把两段文字连在一起。 |
- 做一个变量,叫 name。
- 把
ask [What is your name?] and wait放在 Wizard 绿旗脚本的开头附近。 - 在它下面加上
set [name v] to (answer)。 - 在一块 say 积木里,放进
(join [Hello, ] (name))。 - 点绿旗,输入你的名字,按 Enter。
when flag clicked
ask [What is your name?] and wait
set [name v] to (answer)
say (join [Hello, ] (name)) for (2) seconds
broadcast [gobo hello v] and wait
when I receive [gobo hello v]
say (join (name) [, will you come with me?]) for (2.5) seconds
怎么用: 点绿旗,在输入框里输入你的名字,按 Enter。
基础任务:四种结局 24 分钟
第 1 步:新东西
打开你第 22 课的故事。添加 Castle 1 背景。添加 Key 和 Apple 角色,再加一个 Walk On 按钮。
第 2 步:三个变量
做出 has key、has apple 和 name。全部都选 For all sprites。
第 3 步:讲故事的人重新开始
when flag clicked
set [has key v] to [no]
set [has apple v] to [no]
switch backdrop to [Forest v]
ask [What is your name?] and wait
set [name v] to (answer)
broadcast [forest scene v] and wait
broadcast [fork v]
第 4 步:森林场景打招呼
when I receive [forest scene v]
say (join [Hello, ] (name)) for (2) seconds
say [Gobo is going to the castle today.] for (2.5) seconds
say [Click the apple to pack it. Then choose a path!] for (3) seconds
第 5 步:苹果和钥匙
when backdrop switches to [Forest v]
show
when backdrop switches to [Woods v]
hide
when backdrop switches to [Underwater 1 v]
hide
when this sprite clicked
set [has apple v] to [yes]
hide
when backdrop switches to [Forest v]
hide
when backdrop switches to [Woods v]
show
when backdrop switches to [Castle 1 v]
hide
when this sprite clicked
set [has key v] to [yes]
hide
第 6 步:树林场景和 Walk On
when I receive [woods scene v]
say [Look! Something shiny!] for (2) seconds
say (join (name) [, click it if I should take it.]) for (2.5) seconds
第 7 步:门
when I receive [go door v]
switch backdrop to [Castle 1 v]
broadcast [door scene v] and wait
if <<(has key) = [yes]> and <(has apple) = [yes]>> then
switch backdrop to [Castle 3 v]
broadcast [friend ending v] and wait
else
if <(has key) = [yes]> then
switch backdrop to [Castle 3 v]
broadcast [hungry ending v] and wait
else
broadcast [locked ending v] and wait
end
end
say [The end!] for (2) seconds
第 8 步:每个结局里谁说什么
when I receive [door scene v]
say [Here is the castle door.] for (2) seconds
when I receive [locked ending v]
say [Oh no. The door is locked.] for (2) seconds
say [I needed a key!] for (2) seconds
when I receive [lake ending v]
say [Splash! I can swim!] for (2) seconds
say [Hello, fish!] for (2) seconds
when backdrop switches to [Castle 1 v]
go to x: (-10) y: (-120)
when backdrop switches to [Castle 3 v]
switch costume to [dragon-a v]
show
when I receive [friend ending v]
say (join [An apple! Thank you, ] (name)) for (2.5) seconds
switch costume to [dragon-b v]
say [Hop on, Gobo! Let's fly!] for (2.5) seconds
when I receive [hungry ending v]
say [Hello, Gobo. I am so hungry.] for (2.5) seconds
say [Come back with an apple!] for (2.5) seconds
湖是第四个结局。做一条新消息,叫 lake ending。在 Wizard 的湖那条路里,还有 Gobo 的湖那组积木里,都选它。
第 9 步:找到全部四个结局
玩四次。每次拿不同的东西。你能找到每一个结局吗?
怎么用: 点绿旗,在输入框里输入你的名字,按 Enter。想拿苹果就点苹果。然后点 The Woods 或 The Lake。在树林里,想拿钥匙就点钥匙。然后点 Walk On。
第二次玩的时候,没有钥匙门也开了。
少了重置。set [has key v] to [no] 必须放在绿旗脚本的最上面。
就算有钥匙,门也总是锁着的。
看看 Key 设的是什么。yes 和 yes (多一个空格)是不一样的。也可能是 Key 的积木在下拉菜单里选错了变量。
它说的是 “Hello,Mia”,没有空格。
点进 join 的第一个格子,在逗号后面打一个空格。
下一个故事开始时,Dragon 还在飞。
它的 Castle 3 信号需要 switch costume to [dragon-a v]。朋友结局让它停在了造型 b。
每个结局里都有你的名字
- 四个结局都至少用一次读故事的人的名字。
- 只在开头问一次名字。
Teacher note
The lazy fix is a second ask [What is your name?] and wait in each ending. It works and it is wrong — the brief says once. Every line only needs (join [I needed a key, ] (name)) reading the variable.
两边都有字
一个 join 把两样东西连在一起。Dragon 想说下面这句话,名字在中间:
Thank you, Mia! You are very kind.(谢谢你,Mia!你真好。)
怎么用: 点绿旗,在输入框里输入你的名字,按 Enter。拿苹果,点 The Woods,拿钥匙,然后点 Walk On。
Teacher reveal — a join inside a join
say (join (join [Thank you, ] (name)) [! You are very kind.]) for (2.5) seconds
The inner join makes Thank you, Mia. The outer one adds the rest. Pupils often build the outer join first and then cannot find a slot for the name — start from the inside.
一个背包
- Gobo 捡起一样东西时,它会滑到右上角。
- 在每个场景里,它都留在那里,直到故事重新开始。
- 没拿的东西,在 Gobo 往前走时还是会消失。
怎么用: 点绿旗,在输入框里输入你的名字,按 Enter。点苹果,然后点 The Woods,再点钥匙,然后点 Walk On。
Teacher reveal — the key
when flag clicked
go to x: (-110) y: (-130)
hide
when backdrop switches to [Woods v]
show
when backdrop switches to [Castle 1 v]
if <(has key) = [no]> then
hide
end
when this sprite clicked
set [has key v] to [yes]
glide (0.5) secs to x: (200) y: (150)
The cue that used to hide the key now asks first. The apple is the same idea, gliding to (150, 150). The flag script matters: without it, the key starts the next story in the corner.
魔法词
- 如果 Gobo 没有钥匙,门会问魔法词。
- 魔法词是 please。它能打开门,就像钥匙一样。
- 有钥匙的话,门就不会问。
怎么用: 点绿旗,在输入框里输入你的名字,按 Enter。点 The Woods,不拿钥匙,点 Walk On,然后输入 please,按 Enter。
总结 3 分钟
- 故事运行的时候,变量会记住读故事的人做了什么。
- 开头要把它设回去,不然下一个故事也会记住。
if <(has key) = [yes]> then让很久以前的事改变现在发生的事。<<> and <>>需要两边都成立。最难的检查放在最前面。- 只问一次。把
(answer)复制到一个变量里。然后你想在哪里用(join [Hello, ] (name))都可以。
- 故事状态
- 故事现在记住的所有东西,比如你带着什么、你的名字。
- 重置(reset)
- 把每个变量都放回开始时的样子。
- join(连接)
- 把两段文字连成一段。
- and(而且)
- 只有两边都成立,它才成立。
交作业
保存你的故事,发给老师。下一课:做一个标题画面。你还要数一数你找到了几个结局。