Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By : Michael Badger
Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By: Michael Badger

Overview of this book

Table of Contents (18 chapters)
Scratch 2.0 Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – scanning a text string to build a list of words


The main task in this project is to look for spaces and create new entries in a list when we find one. Let's step through the blocks:

  1. For the teller, create a new list named scanned words and a new variable named letter#.

  2. Since we will recreate the scanned words list each time we get a new question from the seeker, we need to delete all the items before we analyze the new answer block value. Drag a delete (all) from (scanned keywords) list from the Data palette to the Scripts area.

  3. Next, set the letter# variable to 1, which will track our progress through the answer value.

  4. To iterate through the characters in the answer value, attach a repeat (length of (answer)) block to the stack.

  5. Then, add an if () then else block. We will evaluate the current character of the answer value to determine if it is equal to a space. The Boolean expression will be as follows: ((letter (letter#) of (answer)) = ( )). You need to actually type a space...