- Learnt28 min · a variable that remembers, a door that checks, and, your name
- Basic24 min · four ways the story can end
- Challenge 1–327 min · names everywhere, words on both sides, a backpack
- Extrabonus · the magic word
Review — where we got to 5 min
- A story map shows every scene and every fork.
- A button is a sprite.
when this sprite clicked+ a broadcast makes a choice. - Every button hides on every path’s message.
Quick-fire
You click The Lake. The Lake button hides, but The Woods button stays on the screen. What is missing?
Reveal the answer
The Woods button has no when I receive [go lake v] + hide. It only hides on its own message.
Today’s Topic 3 min
- A variable that remembers:
(has key) - A door that checks it
- Two things at once:
<<> and <>> ask [What is your name?] and wait,(answer)and(join [Hello, ] (name))
Learning outcome
By the end of this lesson you will be able to:
- Use a variable to remember what the reader did.
- Make the story check it, with if / else and with and.
- Ask the reader’s name once, and put it into lines of the story.
Learnt — a story that remembers 28 min
The story forgets everything
Right now, nothing you do in the woods matters later. The castle door cannot know what happened in the woods. A variable can remember it.
- Open Variables and click Make a Variable.
- Call it has key. Keep For all sprites.
- Tick its box, so you can watch it on the Stage.
Picking up the key
Add the Key sprite. It lies in the woods. One click picks it up.
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
The reader needs time to decide. So the woods path stops and waits for a Walk On button. No timer, no hurry.
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
The door checks
At the door, the story reads the variable and goes one way or the other:
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
The Wizard also sets set [has key v] to [no] at the very start, before the woods.
How to use this: Click the green flag. Click the key if you want Gobo to take it, then click Walk On.
Two things at once: and
In the forest there is an apple. The Dragon behind the door is hungry. Make a second variable, has apple, and let the apple set it when clicked.
<<> and <>> is in Operators. It is true only when both sides are true.
| has key | has apple | What happens |
|---|---|---|
| yes | yes | The Dragon eats the apple and becomes Gobo’s friend |
| yes | no | The door opens, but the Dragon is too hungry to play |
| no | yes or no | The door is locked |
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
How to use this: Click the green flag. Click the key, the apple, both or neither, then click Walk On.
Your name in the story
| Block | Category | What it does |
|---|---|---|
ask [What is your name?] and wait | Sensing | Shows the question and a box. Waits until the reader presses Enter. |
(answer) | Sensing | What the reader typed last time. |
(join [Hello, ] (name)) | Operators | Sticks two pieces of text together into one. |
- Make a variable called name.
- Put
ask [What is your name?] and waitnear the start of the Wizard’s flag script. - Under it, add
set [name v] to (answer). - In a say block, drop in
(join [Hello, ] (name)). - Click the flag, type your name, press 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
How to use this: Click the green flag, then type your name in the box and press Enter.
Basic — four ways to end 24 min
Step 1 — new things
Open your Lesson 22 story. Add the Castle 1 backdrop, the Key and Apple sprites, and a Walk On button.
Step 2 — three variables
has key, has apple and name. All For all sprites.
Step 3 — the storyteller starts fresh
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]
Step 4 — the forest scene greets the reader
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
Step 5 — the apple and the key
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
Step 6 — the woods scene and 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
Step 7 — the door
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
Step 8 — who says what in each ending
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
The lake is the fourth ending. Make a new message, lake ending, and pick it in the Wizard’s lake path and in Gobo’s lake stack.
Step 9 — find all four endings
Play four times. Take different things each time. Can you reach every ending?
How to use this: Click the green flag, then type your name in the box and press Enter. Click the apple if you like, then click The Woods or The Lake. In the woods, click the key if you like, then click Walk On.
The door opens on the second play, with no key.
The reset is missing. set [has key v] to [no] must be at the top of the flag script.
The door is always locked, even with the key.
Look at what the Key sets. yes and yes (with a space) are not the same. Or the Key’s block picks a different variable in its dropdown.
It says “Hello,Mia” with no space.
Click into the join’s first box and type a space after the comma.
The Dragon is still flying at the start of the next story.
Its Castle 3 cue needs switch costume to [dragon-a v]. The friend ending left it on costume b.
Your name in every ending
- All four endings use the reader’s name at least once.
- Ask for the name only once, at the start.
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.
Words on both sides
One join sticks two things together. The Dragon wants to say this, with the name in the middle:
Thank you, Mia! You are very kind.
How to use this: Click the green flag, then type your name in the box and press Enter. Take the apple, click The Woods, take the key, then click 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.
A backpack
- When Gobo picks something up, it glides to the top-right corner.
- It stays there, in every scene, until the story starts again.
- Things left behind still disappear when Gobo moves on.
How to use this: Click the green flag, then type your name in the box and press Enter. Click the apple, then The Woods, then the key, then 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.
The magic word
- If Gobo has no key, the door asks for the magic word.
- The word is please. It opens the door as well as the key does.
- With the key, the door does not ask at all.
How to use this: Click the green flag, then type your name in the box and press Enter. Click The Woods, leave the key, click Walk On, then type please and press Enter.
Summary 3 min
- A variable remembers what the reader did, for as long as the story runs.
- Set it back at the start, or the next story remembers too.
if <(has key) = [yes]> thenlets something from long ago change what happens now.<<> and <>>needs both sides true. Put the fussiest check first.- Ask once, copy
(answer)into a variable, then(join [Hello, ] (name))wherever you like.
- Story state
- Everything the story remembers right now: what you carry, your name.
- Reset
- Putting every variable back to how it starts.
- Join
- Sticking two pieces of text into one.
- And
- True only when both sides are true.
Hand in
Save your story and send it to your teacher. Next lesson: a title screen, and a count of every ending you have found.