You could use the IF block (control tab) with the "=" operator (operators tab) and the "answer" block (sensing tab)
So, something like this should do it:
When green flag clicked
ask "what do you want to do?"
if <answer = jump>
broadcast do_a_jump
endif
if <answer = fly>
broadcast go_fly
endif
The downside of this approach, though, is if the user types in something that doesn't match any of the choices, then there is no error message. There's a couple of ways to deal with that too, maybe the simplest would be to define a variable and keep track of when a good answer is found. So, let's define a variable good_answer and use it like this:
When green flag clicked
ask "what do you want to do?"
set good_answer to no
if <answer = jump>
set good_answer to yes
broadcast do_a_jump
endif
if <answer = fly>
set good_answer to yes
broadcast go_fly
endif
if <good_answer = no>
say "Sorry - I did not understand your answer. Please type "jump" or "fly"
endif
Offline
Paddle2See wrote:
You could use the IF block (control tab) with the "=" operator (operators tab) and the "answer" block (sensing tab)
So, something like this should do it:
When green flag clicked
ask "what do you want to do?"
if <answer = jump>
broadcast do_a_jump
endif
if <answer = fly>
broadcast go_fly
endif
The downside of this approach, though, is if the user types in something that doesn't match any of the choices, then there is no error message. There's a couple of ways to deal with that too, maybe the simplest would be to define a variable and keep track of when a good answer is found. So, let's define a variable good_answer and use it like this:
When green flag clicked
ask "what do you want to do?"
set good_answer to no
if <answer = jump>
set good_answer to yes
broadcast do_a_jump
endif
if <answer = fly>
set good_answer to yes
broadcast go_fly
endif
if <good_answer = no>
say "Sorry - I did not understand your answer. Please type "jump" or "fly"
endif
Alternately, for the error example, you could do this:
when green flag clicked ask [what do you want to do?] and wait if <(answer) = [jump]> broadcast [jump v] else if <(answer) = [fly]> broadcast [fly] else say [Sorry - I did not understand your answer. Please type "jump" or "fly"]
This checks if it is "jump", and if it is not, it checks if it's "fly", and if it's not, it gives the error message.
Offline
11tancakm wrote:
it does not work after a while it says what i want it to say if answer is wrong. is there any other way.
Everything we told you should work; I don't know why it's not. Are you doing it too quickly? Did you forget a block?
Offline
Paddle, I think I've elaborated on your "error message" one. You can find the script here; it uses the "Repeat until" block to make it so that the answer is an acceptable one before it executes the broadcasts.
EDIT: Woah, I didn't realise how formal that sounded
Last edited by RedRocker227 (2012-01-26 10:47:46)
Offline