For every question the seeker asks, the teller has a response. Let's use the join block to add a little "thoughtfulness" to the response.
Run the script several times to test the code to observe the teller's response. Remember, we previously built this script to provide a different answer on every fifth question, which means our new code will not always run.
Using the join block, we combined a constant phrase with the phrase contained in the your_fortune block, a variable. We could have achieved the same results with say blocks, but we would have needed to use two say blocks to accomplish the same thing. Also, the join block gave the script a different tempo than what we would have been able to achieve using multiple say blocks.
Like many other blocks in Scratch, we can nest multiple join blocks. This allows us to join multiple text phrases to form complex thoughts and paragraphs, as the following screenshot demonstrates.
In addition to the join block, we can also manipulate text using the letter of and length of Operator blocks. The letter of block identifies the specified position in the supplied text phrase. The length of block, reports the number of characters in a phrase.
Consider the following screen shot, which is a help screen from Scratch.
We can also use the comparison blocks, (>, <, and =) to evaluate one string against another. Consider the following screen shot.
The code in the screen shot checks to see if the keyboard input in the answer block, matches any of the items in the questions list. Just like comparing two numbers, if a match is made, the statement evaluates to true; otherwise it's false.
Our focus has been on using lists and variables to drive the action in our game. If you wanted to expand on this game, try adding graphical effects to the sprites and creating a design that begins to tell a story.
Using the concepts in this chapter, you could create other games of chance, such as blackjack, bingo, or a lottery number predictor. The text operators give you a lot of flexibility to create more complex and natural conversations.