Now that you have a chatbot with a personality, you’re going to program it to talk to you.
Click on your chatbot sprite, and add this code to it so that when it's clicked
, it asks for your name
and then says "What a lovely name!"
.
Click on your chatbot to test your code. When the chatbot ask for your name, type it into the box that appears at the bottom of the Stage, and then click on the blue mark, or press Enter.
Right now, your chatbot replies “What a lovely name!” every time you answer. You can make the chatbot’s reply more personal, so that the reply is different every time a different name is typed in.
Change the chatbot sprite’s code to join
“Hi” with the answer
to the “What’s your name?” question, so that the code looks like this:
By storing the answer in a variable, you can use it anywhere your project.
Create a new variable called name
.
Now, change your chatbot sprites’s code to set the
variable to name
answer
:
Your code should work as before: your chatbot should say hi using the name you type in.
Test your program again. Notice that the answer you type in is stored in the
variable, and is also shown in the top left-hand corner of the Stage. To make it disappear from the Stage, go to the name
Variables
blocks section and click on the box next to
so that it is not marked.name