Working with sound and text
In Scratch a sprite can talk with the user. For this we use “ask ... and wait” from Sensing: when the program runs, a typing box appears at the bottom of the stage and the user types the answer and presses Enter. The typed reply is held in the “answer” block. The “say” block from Looks shows words in a speech bubble. To combine several pieces of text use the “join” block from Operators: for example “Great choice: ” and the answer join into “Great choice: apple”. For sound the Sound category has “start sound” and “play sound until done”. The “if ... then” block runs its commands only when the condition is true, for example if the answer equals 5 it says “Correct!”. For safety: never type a password, home address or phone number into your project or someone else’s; let sprites ask only harmless questions such as a name or favourite colour.
A librarian asks “which book do you need?” and, depending on the answer, sends you to the right shelf. A question, an answer and an action based on the answer are the basis of a dialogue. In a program the “ask and wait” block works like this.
A programmer writes software that talks with the user, a game designer composes a character’s replies, and an author of a help program plans the questions.
Ask a friend a question, wait for the answer and react differently according to it; write the chain in your notebook as “question → answer → reaction”.
“Chat program”: pairs build a short conversation (2 questions, 2 answers) with a favourite sprite. Another pair tests it and finds mistakes or unclear spots.