Home
Project Folders
Teacher Resources
Student Resources
En ESPAÑOL
How Do I?
Vocabulary
MWForum
Site Map
Search
Our Team

critter chat 1 2 3 4 5 6 7
Critter Chat Expert 5
Download
11 KB


Goal:   Customize some more with Variables.


Screenshot


Vocabulary:   make

Code
Shapes
Project Map

to startup
set "question "pos [-200 140]
set "announce "pos [-200 140]
text1, ct hidetext
setbg 0
t1, setsh "critter
conversation
end

to conversation
question [Hi! Do you want to talk? (Type YES or NO.)]
if answer = "no [stop]
if empty? answer [stop]
question [What is your name?]
if empty? answer [stop]
make "yourname answer
text1, ct insert "Hi, insert char 32 insert :yourname insert "! showtext
question (se :yourname [, I don't have a name.   Please give me a name.] )
if empty? answer [stop]
text1, ct insert "I'm insert char 32 insert answer insert "!
question (se :yourname [, what color do you like best: red, yellow, orange, green, blue, or violet?] )
if empty? answer [stop]
changecolor
question (se [ I like] answer [too, ] :yourname [.   Which sport do you like best: football, baseball, basketball, or soccer?] )
insist
announce (se [I like] answer [best, too! Watch me turn into a ball,] :yourname "! )
setsh answer
text1, ct insert [I'm a] insert char 32 insert answer if answer = "soccer [insert "ball] insert "!
end

to changecolor
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]
end

to insist
if member? answer [basketball baseball football soccer] [stop]
if empty? answer [stopall]
question [Which sport do you like best: football, baseball, basketball, or soccer? (Spell carefully!)]
insist
end

to Let's_talk_again!
startup
end



Notes

Suppose we would like the program to remember the user's name for the whole conversation.   We need a way to save this name, because answer only remembers the latest answer.  

  1. We can save an answer by creating a variable using make. In this case, the command
    make "yourname answer
    creates a variable called yourname and gives it the value of the most recent answer.   (Be sure to include one quotation mark before the name of the variable.)   Now the computer will remember that answer as long as we want.   Whenever we want to use that name, we can write :yourname and the user's name will be supplied.   (Be sure to include the colon.)




What If?
Try giving your variable a different name instead of yourname.   Does it still work?


Challenge
Create a question-answer conversation in which you include the user's name in at least three questions: at the beginning, the middle, and the end of a question.


On Your Own - Project Ideas
Create a question-answer conversation in which you save more of the user's answers as variables and use some or all of them in a funny way at the end of the conversation.





© copyright 2001 - 2016  OpenWorld Learning.   All rights reserved.