arrow_back Funky Phrases
This add-on will teach you about a new way that computer scientists store information in computers, and at the end, your athlete will say random things that you program.
To make the athlete randomly say different things, first create a place to store phrases to choose from. Computer scientists often store this kind of information in a list.
You already used variables in this club. But, a variable only stores one piece of information, such as a single number, sentence, or true/false value. Lists work like variables, except they hold many different pieces of information, instead of just one.
To create a list, select “make a list” from the data menu. Name the list something like “Funky Phrases” because it will contain different phrases the athlete will say. Then, click “OK.” The list will pop up on the stage. Next, add phrases for the athlete to say. To add a new phrase to the list, either click the “plus” button, or type the phrase into the “add” block in the data menu, and click to add it to the list. Add as many funky phrases to the list as you want. This example uses things like, “CS First Sports was really fun,” “I learned how to create with computers,” and “My teammates helped me out a bunch.” Next, program the athlete to say the phrases you added. Drag out a “say” block, then from the “data” menu, drag out the “item” block. This block picks one item at a time from a list. Snap this block into the “say” block. Click the “say” block to test this. It works, but the athlete only says the first item on the list. Click the dropdown in the “item” block. The number “1” is selected. That means the “item” block only ever looks at the first phrase in the list, so when you click the “say” block, that’s the phase the athlete says. To make the athlete say a random phrase from the list, select “random” from the dropdown menu. Finally, choose when to start off your new code. You have a couple of options: either snap the event to the bottom of the dialogue, or snap a new event block above the “say” block. The example uses a “when this sprite clicked” event to make the athlete say an item from the list every time it is clicked.
Here’s the game plan: Make a list.
Fill the list with fun phrases. Choose an event or a place to insert the “say” block that will pick a random item from the list to say.