In this lesson you will create a robot that first asks you some questions and then generates a username for you based on your answers!
Create a new Scratch project and delete the cat sprite.
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
We're going to use a robot sprite to ask you some questions. The answers to these will help make your username!
Once you've added the 'Retro Robot' sprite form the library, drag it to the middle of the stage area.
To add a sprite from the sprite library follow these steps:
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
We will need to create a variable called 'user name' to store the text of our username as we build it.
When you create a variable, a small orange rectangle appears in the stage area that displays the current value of that variable. We don't need to this display so we're going to add the following code to hide it:
when green flag clicked
hide variable [user name v]
In the Variables palette, create a new variable by clicking the 'Make a Variable' button.
Once you click this button a box will appear asking what you want to call your variable. Give it a name that reminds you what you will be using it for. For example, if you wanted to keep track of your score in a game, you would create a variable called 'score'.
Our robot is going to give the instructions for using the username generator. Add the following code at the bottom of the 'when green flag clicked' blocks of code:
when green flag clicked
say [I am the random username generator robot!] for [5] secs
say [To get a username, answer these questions...] for [5] secs
The start of the username is going to be the first letter of the person's name. We can get this by asking the person what their name is and then taking the first letter of their answer. Add the following code at the bottom of the when clicked blocks of code:
when green flag clicked
say [I am the random username generator robot!] for [5] secs
say [To get a username, answer these questions...] for [5] secs // insert the new code below here
ask [Whats your first name?] and wait
set [user name v] to (letter (1) of (answer))