Time for action - ask your question

Select the seeker sprite, and let's begin.

  1. From the Control palette, add the when seeker clicked block to the scripts area.
  2. From the Sensing palette, add the ask block to the when seeker clicked block.
  3. Type a question in the ask block. This is the question, the sprite seeker will ask.
  4. Add a broadcast block to the script and select the message fortune.
  5. Click the seeker to display the ask box on the stage.
    Time for action - ask your question
  6. Type your question, and then either click the check mark on the ask field or press Enter on your keyboard. The teller responds with your fortune.

What just happened?

Let's hope our teller believes in the old mantra, "there are no dumb questions."

When we clicked on the teller, the seeker used a speech bubble to ask the question we defined in the ask block. In my example, the seeker's question was "Ask your question."

The ask block forces the script to wait for keyboard input, which means our project stopped until we provided input into the ask box. When we pressed the Enter key, the broadcast block woke the teller up, and we got our fortune.

Add the question to the list

The keyboard input gets stored in the answers variable, which can be found in the Sensing palette. We're going to use the answers variable along with additional string operators to add each new question to the seekers questions list.

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

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