- 学一学28 分钟 · 两种记忆、标题画面、只数一次、Play Again
- 基础任务24 分钟 · 完成 The Castle Quest(城堡探险)
- 挑战 1–327 分钟 · 用句子说出计数、四个都找到、名字只问一次
- 加分任务加分 · Secret Path(秘密小路)
复习:我们学到哪里了 5 分钟
(has key)和(has apple)记住读故事的人捡到了什么。- 故事开始时,讲故事的人把它们设回 no。
<<> and <>>需要两边都成立。最难的检查放在最前面。- 只问一次。然后在哪里都可以用
(join [Hello, ] (name))。
快问快答
你把故事玩了两次,中间没有按绿旗。第二次,门开了,可是你没拿钥匙。为什么?
看答案
has key 还是第一个故事留下的 yes。新故事开始时,必须有积木把它设回 no。今天我们要仔细选择哪些东西要重置,也要选择哪些东西不能重置。
今天的主题 3 分钟
- 两种记忆:只管一个故事的,和一直保留的。
- 一个由消息开始的标题画面。
(endings found)是一个绿旗不会碰的计数。- 用
<not <>>,每个结局只数一次。 - Play Again 和 Clear Endings。
学习目标
上完这节课,你能够:
- 做一个标题画面,给它一个 Start 按钮和一个 Clear Endings 按钮。
- 每个结局只数一次,就算你到过它很多次。
- 选择新故事要重置哪些变量,保留哪些变量。
学一学:可以再玩一次的故事 28 分钟
两种记忆
在一个好玩的故事游戏里,你会想找到所有结局。所以它要记住两种东西。
| 变量 | 记住什么 | 谁把它设回去 |
|---|---|---|
(has key), (has apple) | 这一个故事里发生了什么。 | 每个新故事。 |
(endings found) | 你一共找到了几个结局。 | 只有 Clear Endings 按钮。 |
标题画面
现在绿旗不会开始故事了。它会显示标题画面:
when flag clicked
switch backdrop to [Castle 2 v]
broadcast [title screen v]
有三个新角色在等这条消息。它们是一张标题卡、一个 Start 按钮和一个 Clear Endings 按钮。
when I receive [title screen v]
show
when this sprite clicked
broadcast [new story v]
when I receive [new story v]
hide
when I receive [title screen v]
show
when I receive [new story v]
hide
when this sprite clicked
set [endings found v] to (0)
那故事呢?拿出 Wizard 原来的 when flag clicked 那组积木。把它的帽子积木换成 when I receive [new story v]。里面别的都不用改。
怎么用: 点绿旗。点 Clear Endings,注意看 endings found。然后点 Start。
每个结局都是一条消息
上节课,你给每个结局都做了自己的消息。它们是 lake ending、locked ending、hungry ending 和 friend ending。这让计数变得很容易。每条消息都可以再多一个脚本来接收。
第一个想法是错的:
when I receive [lake ending v]
change [endings found v] by (1)
每个结局只数一次
每个结局有一个 yes / no 变量。它们是 found lake、found locked、found hungry、found friend。计数只在第一次增加。
when I receive [lake ending v]
if <not <(found lake) = [yes]>> then
set [found lake v] to [yes]
change [endings found v] by (1)
end
怎么用: 点绿旗。点 The Lake 三次,注意看 endings found。然后点 The Castle,再点 Clear Endings。
结束,和 Play Again
Wizard 有两组结局积木:门和湖。两组最后都要再加一块积木:broadcast [the end v]。一个 Play Again 按钮会接收它。
when flag clicked
hide
when I receive [the end v]
show
when this sprite clicked
broadcast [new story v]
when I receive [new story v]
hide
| 你按了 | has key 和 has apple | endings found |
|---|---|---|
| Start 或 Play Again。 | 设成 no。 | 保留。 |
| 绿旗。 | 保留(直到你按 Start)。 | 保留。 |
| Clear Endings。 | 保留。 | 设成 0。 |
基础任务:完成 The Castle Quest 24 分钟
第 1 步:标题画面的东西
- 添加 Castle 2 背景。
- 画一个标题。新建一个角色。用 T 工具和大大的字母写上 The Castle Quest。
- 用 Button2 再做三个按钮:Start、Clear Endings 和 Play Again。把这四个角色都藏起来。
第 2 步:五个变量
做出 endings found。然后给每个结局做一个 yes / no 变量:found lake、found locked、found hungry、found friend。舞台上只显示 endings found。
第 3 步:Wizard 的开头
做出那个短的绿旗脚本。然后把原来的绿旗积木从它的帽子积木上拉开。换上 when I receive [new story v]:
when I receive [new story v]
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 步:按钮
照着“学一学”,给 Start 和 Play Again 加上它们的积木。标题卡收到 title screen 时显示,收到 new story 时隐藏。Clear Endings 会忘掉所有结局:
when I receive [title screen v]
show
when I receive [new story v]
hide
when this sprite clicked
set [endings found v] to (0)
set [found lake v] to [no]
set [found locked v] to [no]
set [found hungry v] to [no]
set [found friend v] to [no]
第 5 步:四个计数脚本
在 Wizard 身上,照着“学一学”做出 lake ending 的计数器。把它复制三次。在每个复制品上,改掉消息。两个下拉菜单也都要改。
第 6 步:每条路的结尾
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
broadcast [the end v]
when I receive [go lake v]
switch backdrop to [Underwater 1 v]
broadcast [lake ending v] and wait
say [Gobo plays with the fish all day.] for (2.5) seconds
say [The end!] for (2) seconds
broadcast [the end v]
第 7 步:整理标题画面
上一个故事里的东西不能出现在标题画面上。
when I receive [title screen v]
hide
when backdrop switches to [Castle 2 v]
go to x: (160) y: (-100)
第 8 步:把它们全找出来
一直玩,直到找到全部四个结局。有几次在中间按一下绿旗。在你点 Clear Endings 之前,计数永远不能变少。
怎么用: 点绿旗,然后点 Start。在输入框里输入你的名字,按 Enter。想拿苹果就点苹果。然后点 The Woods 或 The Lake。在树林里,想拿钥匙就点钥匙,然后点 Walk On。点 Play Again 再玩一次。
我一按绿旗,计数就变回 0。
还有一个 when flag clicked 脚本在设置 (endings found)。在每个角色和舞台里找一找。只有 Clear Endings 可以设置它。
同一个结局被数了两次。
那个计数器少了 if。或者你复制以后,它的下拉菜单里还写着 found lake。
第一个结局永远数不到。
检查写的是 <(found lake) = [no]>。新变量是 0,不是 no。用 <not <>> 的那个版本。
点 Play Again 没有反应。
Wizard 的故事积木还是从 when flag clicked 开始。它的帽子积木必须是 when I receive [new story v]。
用句子说出计数
- 在标题画面上,Wizard 说出你找到了几个结局。
- 用一个完整的句子:You have found 2 of 4 endings.(你找到了 4 个结局里的 2 个。)
- 气泡一直留着,直到故事开始。
Teacher reveal
when I receive [title screen v]
say (join (join [You have found ] (endings found)) [ of 4 endings.])
A join inside a join, as in Lesson 23. Plain say [Hello!] with no seconds keeps the bubble up; the Wizard’s first line in the story replaces it. Watch for the two spaces, either side of the number.
四个都找到了
- 当 endings found 是 4 时,标题画面会说 You found every ending!(你找到了所有结局!)
- Dragon 飞到标题画面上来开派对。
- 不到 4 的时候,标题画面还是普通的样子。
怎么用: 点绿旗,看看标题画面。点 Clear Endings,然后再点一次绿旗,比较一下。
Teacher reveal
when I receive [title screen v]
if <(endings found) = (4)> then
switch costume to [dragon-b v]
go to x: (80) y: (30)
show
else
hide
end
On the Dragon, replacing its plain title-screen hide. The Wizard’s line from Challenge 1 gets the same if / else.
名字只问一次
- 第一个故事会问读故事的人的名字。
- Play Again 和 Start 不会再问。它们已经知道了。
- Clear Endings 也会忘掉名字。因为有新的读者要开始了。
怎么用: 点绿旗,然后点 Start。在输入框里输入你的名字,按 Enter。玩完故事,然后点 Play Again。
Teacher reveal
if <(name) = []> then
ask [What is your name?] and wait
set [name v] to (answer)
end
In the new story stack, around the ask. Clear Endings gains set [name v] to []. The empty box is the whole trick — it is how the story knows nobody has told it a name yet.
Secret Path(秘密小路)
- 找到全部四个结局。然后岔路口会出现第三个按钮:Secret Path。
- 它通往一个秘密结局。Gobo 和 Dragon 飞过城堡上空。
- 秘密结局不会改变 endings found。它是一个奖励,不是第五个结局。
怎么用: 点绿旗,然后点 Start。在输入框里输入你的名字,按 Enter。按钮出现后,点 Secret Path。
总结 3 分钟
- 有些东西只保留一个故事,有些东西一直保留。
- 只有积木改变它,变量才会改变。所有绿旗脚本里都不要碰计数。
- 标题画面是一条消息。故事从另一条消息开始。
- 每个结局用一个 yes / no 变量,再加上
<not <>>。这样每个结局只数一次。 - Play Again 重置故事。Clear Endings 重置计数。
- 标题画面
- 玩家看到的第一个画面。它在游戏或故事开始之前出现。
- 计数器
- 一个每次加一的变量。
- 标记变量(yes / no)
- 一个告诉你某件事是不是已经发生了的变量。
- 重玩
- 再玩一次,去找第一次错过的东西。
发布作品
选择你的路这个游戏就全部完成了。分享之前:
- 点 Clear Endings,这样新的读者会从 0 开始。
- 在作品页面上写两行说明。说清楚要点什么,还有一共有四个结局。
- 如果你有账号,就把它分享到 scratch.mit.edu 上。把链接发给老师。
下一课,我们开始一个新作品:怪兽制造机。