| Critter Chat 4 |
|
|
|
| |
if you cannot see the project |
|
Goal: Compose customized sentences.
Vocabulary: empty?, se (sentence), stopall
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]
text1, ct insert "Hi, insert char 32 insert answer insert "! showtext
question (se answer [, 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 [What color do you like best: red, yellow, orange, green, blue, or violet?]
if empty? answer [stop]
changecolor
question (se [ I like] answer [, too. 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!] )
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 We need a way to stop the questions if the user clicks cancel or gives no answer.
- After every question in the conversation procedure, use the command
if empty? answer [stop]
to check for an answer and stop the procedure if the answer box is empty.
- Use se (sentence) to include an answer in the next question or in an announcement. Put parentheses ( ) around se, the answer, and everything else that you want to include.
- In the insist procedure, if the user clicks cancel or gives no answer, we do not just want to stop the insist procedure, we also want to stop the conversation procedure. We need to stop everything. For this, we need stopall in this command:
if empty? answer [stopall]
What If?
What happens if you change this line: if empty? answer [stopall] to this:
if empty? answer [announce "Good-bye! stopall]
Challenge
Can you write your own questions which include the user's answers in them?
If the user doesn't answer a question, can you make the critter say or do something funny before stopping the conversation?
|