Goal: Write to text boxes, change the Critter´s world.
Vocabulary: startup, ct (cleartext), hidetext, showtext, insert, setbg, set, pos
set "question "pos [-200 140]
set "announce "pos [-200 140]
text1, ct hidetext
question [Hi! What is your name?]
question [I don't have a name. Please give me a name.]
text1, insert answer
question [Thanks! I like that name. What color do you like best: red, yellow, orange, green, blue, or violet?]
if answer = "red [setbg "red]
if answer = "yellow [setbg "yellow]
if answer = "orange [setbg "orange]
if answer = "green [setbg "green]
if answer = "blue [setbg "blue]
if answer = "violet [setbg "violet]
When a procedure is named startup
, it will begin running as soon as you open the project. Here, startup
does four things:
- In this startup procedure,
set "question "pos [-200 140] sets the pos ition of the question dialog box. (The two numbers set the x and y coordinates of the top left corner of the box.) You may choose different numbers to position the box.
- set "announce "pos [-200 140] sets the position of the announcement dialog box. Again, you may choose different numbers.
- text1, ct tells the text box named text1 to ct ("clear text"). This erases everything in the text box.
- Hidetext hides the text box.
- Setbg means "set background color." It needs a number as input. 0 is white. This makes sure the background color is white.
- The final command in the startup procedure is the name of another procedure called conversation. Since this command is placed in the startup procedure, it will begin running automatically when the project is opened.
- In the conversation procedure, you may write your own questions. But do respond to one answer like this:
text1, insert answer inserts the answer into the text box named text1. (Text can be inserted into the text box even when it is invisible.)
- Showtext makes the text box visible.
- The last line of the conversation procedure calls the changecolor procedure.
- Each line of the changecolor procedure is an if statement.
if answer = "red [setbg "red] means, "If the text typed as an answer is the word red, then set the background color to red."
The other if statements deal with other possible colors that might be typed as an answer. When an if statement is true, the instructions in brackets will run. If the statement is not true, the instructions in brackets will be ignored. If your visitor types a word that is not among these colors, or uses a different spelling, then nothing will happen; the background color will not change.
What happens if a user types a different color in the last question box, rather than one of the six listed colors?
Can you set up a way for the user to start the conversation again, after it has finished?
On Your Own - Project Ideas
Create your own conversation which writes one or more answers to a text box or launches other actions.