Learning Goals 3 min
This is the Cluster C capstone project. You'll glue together everything from L02-12 through L02-18 into one bilingual chatbot. By the end you will be able to:
- Chain two ask [] and wait blocks one after the other, knowing that the (answer) reporter only ever holds the most recent reply — so you must save the first answer into a variable before asking the second question.
- Use if <> then else with a string comparison <[] = []> on (answer) to make the bot branch on what the human typed.
- Use the (join [] []) operator to glue a greeting onto a saved name, so the bot can say "Hai, Aisyah!" instead of just "Hai!".
Warm-Up — predict the chat 8 min
Two puzzles. Eyes only — no Scratch yet.
Puzzle 1 — the forgetful greeter
when flag clicked
ask [What's your name?] and wait
ask [What's your favourite kuih?] and wait
say (join [Hi, ] (answer)) for (2) seconds
You type Aisyah for the first question and kuih lapis for the second. What does the bot actually say?
Reveal the answer
The bot says "Hi, kuih lapis" — not "Hi, Aisyah". The (answer) reporter is not a list. It's a single mailbox that gets overwritten each time you ask a new question. The second ask threw out "Aisyah" and replaced it with "kuih lapis". By the time the say block reads (answer), the name is gone.
Puzzle 2 — predict the branch
ask [Apa khabar?] and wait
if <(answer) = [baik]> then
say [Bagus!] for (2) seconds
else
say [Oh, sorry to hear.] for (2) seconds
end
You type Baik with a capital B. Which branch runs?
Reveal the answer
The else branch — "Oh, sorry to hear." Scratch's = is case-sensitive for letters in different cases when comparing text. Baik and baik are not equal. We'll talk about this in the Concept section and use a small trick to make the bot friendlier.
Today's project gets both of these right. The bot will remember your name, ask a second question in Malay, and branch on the answer — accepting common variations like baik, good, and fine.
New Concept — chaining asks, saving answers, joining strings 14 min
You met ask [] and wait in L02-18. Today we glue three or four of these moves into one bot that holds a real little conversation. Three small ideas hold it together.
Idea 1 — the answer mailbox
Every project has one (answer) reporter, and it stores only the most recent reply. That's it. There's no (answer 1) and (answer 2). There's just (answer), and it changes every time someone uses ask [] and wait.
So if you want to keep the first reply and ask a second question, you must save the first reply into a variable before the next ask block runs. We did variables briefly in early L2 — this is one of the most useful places they show up.
ask [What's your name?] and wait
set [name v] to (answer)
ask [Apa khabar?] and wait
Idea 2 — comparing strings with =
The Operators palette has a hexagonal <[] = []> block. It reports true when both sides are equal, false when they're not. It works for numbers and for text.
- <[baik] = [baik]> → true
- <[baik] = [Baik]> → false (different capitalisation counts as different)
- <(answer) = [baik]> → true only if the human typed exactly
baik
To accept several spellings — baik, good, fine — we chain comparisons with <> or <> from Operators. Each side is its own hexagonal question, joined by "or":
if <<(answer) = [baik]> or <(answer) = [good]>> then
say [Bagus!] for (2) seconds
end
Idea 3 — joining text with the (join) operator
The bot needs to say "Hai, Aisyah!" not just "Hai!". The Operators palette has a round reporter called (join [apple ] [banana]) that glues two pieces of text together and reports the combined result. You can drop it inside any block that takes a round input:
say (join [Hai, ] (name)) for (2) seconds
[Hai, ] — without it the bot would say "Hai,Aisyah" with no breathing room.To build longer greetings like "Hai, Aisyah! Bagus!", nest (join) inside another (join) — the inner one becomes the second piece of the outer one. We'll do this in Step 8.
Idea 4 — if-then-else holds the whole branch
The full bot uses one big if <> then else. The then branch is the friendly Malay reply ("Bagus!"). The else branch is a softer English reply ("Oh, take care!"). Either way, the bot finishes with a goodbye that uses the saved name.
Worked Example — building the bilingual bot 22 min
One pet sprite, one variable, ten steps. This is the guided full build of the whole pet bot — then we run it and ship it.
Step 1 — Start fresh and pick a sprite
New Scratch project. Delete the default cat if you'd like a friendlier face — try the Avery sprite from the library, or stick with the cat. Drag the sprite to roughly the centre of the Stage.
Step 2 — Make the (name) variable
Click the orange Variables palette. Click Make a Variable. Type name. Pick "For this sprite only" (the bot is the only one who needs it). Click OK. A new round reporter (name) appears in the palette.
Step 3 — The flag hat and the first ask
From Events: when ⚑ clicked. From Sensing: ask [What's your name?] and wait. Snap them together.
when flag clicked
ask [What's your name?] and wait
Step 4 — Save the name into the variable
From Variables: set [name v] to (0). Drag the (answer) reporter from Sensing into the round slot, replacing the 0. The block now reads set [name v] to (answer).
Step 5 — Greet by name with (join)
From Looks: say [Hello!] for (2) seconds. From Operators: (join [apple ] [banana]). Drag the join into the say's text slot. In the join, set the left slot to [Hai, ] (with a trailing space) and drag (name) into the right slot.
when flag clicked
ask [What's your name?] and wait
set [name v] to (answer)
say (join [Hai, ] (name)) for (2) seconds
Aisyah, see "Hai, Aisyah". The greeter works.Step 6 — Ask the second question in Malay
From Sensing: another ask [Apa khabar?] and wait. Snap it on. Now the bot greets, then asks how you are.
Step 7 — Add the if-then-else with two equality checks joined by "or"
From Control: if <> then else. From Operators: <> or <>. Drop the "or" into the if's diamond. Then drop two <[] = []> blocks into the or's two slots. Into each equality block's left slot, drag (answer). On the right slots, type baik and good respectively.
Step 8 — Fill the "then" branch (the happy reply)
Inside the then slot of the if-then-else, add a Looks say with a nested (join) that produces "Bagus, Aisyah!":
say (join [Bagus, ] (join (name) [!])) for (2) seconds
"Bagus, " to the result of the inner join, which glues the name to "!".Step 9 — Fill the "else" branch (the gentle reply)
Inside the else slot, add a say [Oh, take care!] for (2) seconds. No join needed — same message for everyone.
Step 10 — The full assembled stack
when flag clicked
ask [What's your name?] and wait
set [name v] to (answer)
say (join [Hai, ] (name)) for (2) seconds
ask [Apa khabar?] and wait
if <<(answer) = [baik]> or <(answer) = [good]>> then
say (join [Bagus, ] (join (name) [!])) for (2) seconds
else
say [Oh, take care!] for (2) seconds
end
say (join [Jumpa lagi, ] (name)) for (2) seconds
Run it. Click the flag. Type Daniel. The bot says "Hai, Daniel". It asks "Apa khabar?". Type baik. It replies "Bagus, Daniel!" and waves goodbye with "Jumpa lagi, Daniel". Try again with tired — you'll get the gentle English reply instead.
What you just built: a project that remembers a piece of input, asks a follow-up, and branches based on what the human says. Every chatbot, quiz, and text adventure ever made is some version of this pattern.
Try It Yourself — three bot extensions 15 min
Goal: Add a third accepted spelling to the happy branch. Right now the bot only smiles for baik or good. Add fine as a third option, so all three trigger the Malay "Bagus!" reply.
if <<<(answer) = [baik]> or <(answer) = [good]>> or <(answer) = [fine]>> then
say (join [Bagus, ] (join (name) [!])) for (2) seconds
else
say [Oh, take care!] for (2) seconds
end
Think: "Or" only takes two slots. Three options means one "or" inside another. This nesting is exactly how (join) chains for long strings.
Goal: Make the bot remember a second fact about the human — their favourite kuih — and use it in the goodbye. Add a third ask after the "apa khabar" branch, save the answer into a new variable (kuih), and rewrite the goodbye to say "Jumpa lagi, Aisyah! Enjoy your kuih lapis!"
ask [What's your favourite kuih?] and wait
set [kuih v] to (answer)
say (join [Jumpa lagi, ] (join (name) [! Enjoy your ])) for (2) seconds
say (kuih) for (2) seconds
"Jumpa lagi, " + name + "! Enjoy your " + kuih.Think: Notice how you used the same pattern twice — ask, then immediately save. That pair of blocks is one logical move; treat it as a unit when you read your own code.
Goal: Add a Malay-only mode. Before the first question, ask "Language? (BM / EN)". Save the reply into a variable (lang). Then use if <> then else to make the bot ask "Siapa nama awak?" instead of "What's your name?" when (lang) is BM, and to greet with "Hai" vs "Hi" accordingly.
when flag clicked
ask [Language? (BM / EN)] and wait
set [lang v] to (answer)
if <(lang) = [BM]> then
ask [Siapa nama awak?] and wait
else
ask [What's your name?] and wait
end
set [name v] to (answer)
if <(lang) = [BM]> then
say (join [Hai, ] (name)) for (2) seconds
else
say (join [Hi, ] (name)) for (2) seconds
end
Think: You've just invented your first setting. A single variable at the top of the script changes the behaviour of many later blocks. Real apps do exactly this with language settings, dark mode, sound on/off.
Mini-Challenge — Priya's broken greeter 5 min
"Why does the bot say my name wrong?"
Priya writes this in class:
when flag clicked
ask [What's your name?] and wait
ask [What's your favourite drink?] and wait
say (join [Hai, ] (answer)) for (2) seconds
say (join [I love ] (answer)) for (2) seconds
She types Priya, then teh tarik. The bot says "Hai, teh tarik" and then "I love teh tarik". Why is the greeting wrong, and what's the smallest fix?
Reveal one valid solution
This is Puzzle 1 from the warm-up, in disguise. The (answer) reporter holds only the most recent reply. By the time the first say block runs, both asks are done — so (answer) is "teh tarik", not "Priya".
The smallest fix is to save the first answer into a variable before the second ask runs:
when flag clicked
ask [What's your name?] and wait
set [name v] to (answer)
ask [What's your favourite drink?] and wait
set [drink v] to (answer)
say (join [Hai, ] (name)) for (2) seconds
say (join [I love ] (drink)) for (2) seconds
Two new blocks — two sets — and now the bot remembers both answers. Every multi-question chatbot you ever build will use this ask, then immediately save pattern.
Recap 3 min
You wrapped up the Sensing Pet Bot arc — eight lessons of senses — by gluing ask [] and wait, (answer), set [name v] to, <[] = []>, <> or <>, (join [] []), and if <> then else into one chatbot. The single most important habit: save the first (answer) into a variable before asking the next question, because the mailbox gets overwritten. Next cluster (Broadcasts, starting L02-20) will give you a way for sprites to talk to each other, not just to the human.
- (answer) reporter
- A single, project-wide mailbox that holds only the most recent reply to an ask [] and wait. Overwritten by every new ask.
- Saving an answer
- The pattern of putting a set [var v] to (answer) block immediately after an ask. The variable preserves the reply for later use.
- String comparison
- <[] = []> works on text as well as numbers. Different capitalisation counts as a different string —
Baik≠baik. - (join) operator
- A round reporter from Operators that glues two pieces of text together. Nest joins inside joins to glue three or more pieces.
- Or operator
- A hexagonal block from Operators that takes two boolean inputs and reports true when at least one is true. Nest "or"s for three-way checks.
Homework 2 min
The Mini Mamak Chatbot. Build a four-question chatbot that takes a fake order at a mamak stall and reads it back to you.
- Open a fresh project. Pick any sprite — a chef costume is nice if you can find one.
- Make four variables: (name), (drink), (food), (spice).
- On when ⚑ clicked: ask "Apa nama?", save to (name). Then ask "Drink? (teh tarik / kopi / milo)", save to (drink). Then ask "Food? (roti / nasi lemak / mee goreng)", save to (food). Then ask "Spice level? (mild / medium / pedas)", save to (spice).
- Read the order back with one big (join)-chain that produces something like "Order for Aisyah: nasi lemak, pedas, with teh tarik."
- Add an if-then-else: if (spice) =
pedas, the chef says "Berani!". Otherwise the chef says "OK!".
Save as HW-L2-19-Mamak-Bot.sb3.
Bring back next class:
- The
.sb3. - Your answer to: "You typed four answers but only used four variables. What would have gone wrong if you had skipped any of the set blocks?"
Heads up for next class: SCR-L02-20 opens a brand-new cluster — Broadcasts. You'll meet broadcast (message v), the way one sprite sends a silent cue that another sprite can react to. The bot you just built only talks to humans; broadcasts let sprites talk to each other.