Time for action - import a list of fortunes

If you haven't already done so, create a new list and name it answers.

  1. To import the list, right-click on the answers list and choose import... Note: This will erase any items you previously added to the answers list.
    Time for action - import a list of fortunes
  2. In the Import List dialog box, browse to the fortunes file you saved on your computer prior to starting this exercise and import it.
  3. Think of a new fortune that is not yet in your answers list. We are going to add it to the list. I'll use "No comment" as my new fortune.
  4. Now, let's add the new fortune to our list. From the Variables palette, find the add block. Replace the default value thing with your new fortune. Make sure the answers list is selected.
    Time for action - import a list of fortunes
  5. Double-click on the add block to add the new item to the end of the answers list.

What just happened?

I don't know about you, but I had a much easier time typing in a text editor than I did typing in the list monitor. Actually, if you took my lead, you copied the Magic 8 ball® responses from Wikipedia and pasted them into a text file. That way, all you had to do was to clean up some formatting.

We did add a new fortune to the list via the add block. The add block always places the new value at the end of the list. Now, my list contains 20 items. As an alternative, we could have updated the original fortunes text file and then re-imported the list.

Reasons to import

It's true that importing a list makes list creation easy. However, we can use the Import List functionality in other creative ways. For example, we could create a game that instructs the player to create a unique list that he or she can import into Scratch. That way, each player can customize the game.

If we create a math game, we could ask the player for a varied set of numbers to make the problems different. You get the idea.

Export a list

Sometimes, we may want to export a list from Scratch to a file. For example, as people play a game, we may want to collect all the scores into a separate list that we can later export to a text file on our computer.

As we create our projects, the contents of a list may change from the original list we imported. In that case, we may want to export the new list.

To export a list, right-click on the list monitor and click export. The file automatically saves to the root installation directory for Scratch. In Windows, that is C:Program FilesScratch.

Pop quiz

  1. If you wanted to group ten related items together, you would create a new:
    • Variable
    • Numbers block
    • List
    • Forever loop
  2. If you want to add many items to a list at one time, how would you do it?
    • Type each item one at a time into the add block
    • Type each item into the list monitor that displays on the stage
    • Export the list from Scratch
    • Create a list in a text file and import it via Scratch

Your fortune is …

Take a moment to add more questions to the seeker sprite's question list.

Now that we have a list of several questions for our seeker to ask and a list of fortunes for our teller to answer, let's create the script that randomly selects a question.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset