This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-01-26 05:45:01

11tancakm
New Scratcher
Registered: 2011-11-28
Posts: 4

Question

how do you make it so if answer is something to brodcast something else.
Please help
its for my school project

Offline

 

#2 2012-01-26 05:54:25

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Question

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


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2012-01-26 07:30:11

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Question

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:

Code:

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

 

#4 2012-01-26 08:33:59

11tancakm
New Scratcher
Registered: 2011-11-28
Posts: 4

Re: Question

<color[  ]is over[ it does not work after a while it says what i want it to say if answer is wrong. is there any other way.

Offline

 

#5 2012-01-26 08:44:29

sci_test
Scratcher
Registered: 2011-06-22
Posts: 100+

Re: Question

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.  hmm  Are you doing it too quickly? Did you forget a block?


[signature removed - please be respectful]
Last edited by scimonster (1970-01-01 00:00:00)

Offline

 

#6 2012-01-26 10:46:27

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Question

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  yikes

Last edited by RedRocker227 (2012-01-26 10:47:46)


Why

Offline

 

#7 2012-01-26 16:32:24

11tancakm
New Scratcher
Registered: 2011-11-28
Posts: 4

Re: Question

i done the wrong script  thnx for help

Offline

 

Board footer