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

#1 2011-02-15 10:13:30

jpsrolls
New Scratcher
Registered: 2010-12-09
Posts: 17

Question with multiple answers

I am doing a question and answer program with my students.  The question I asked is, "What is your favorite sport?"  We had 4 if loops for tennis, golf, swimming and basketball. For each loop, I had a comment such as, "Basketball rocks!" Since I couldn't possibly think of every sport, I put in an if-else loop for those situations, and the cat would say, "that sounds like a fun sport, too!".

I found the program did not work when I used the say block, but did work when I used the say for 2 sec block.

could someone explain to me why this is so?  I would like to have an explanation for my students.
Thanks in advance1  Judy

Offline

 

#2 2011-02-15 10:18:12

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Question with multiple answers

The say block makes a sprite say something, then immediately (within the time span of one frame) runs the blocks below it.  Also, it will say whatever you wrote until you make it say something else or make it say "  "(equivalent to making it stop talking).

Are there any blocks underneath your say block, or are there any scripts that run after this one plays?  Maybe a stop script block, a block making it say something else?

Also, do you have any means that we can see the script itself?  That'd make finding the problem a lot easier.

Last edited by Kileymeister (2011-02-15 10:19:12)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#3 2011-02-15 13:13:55

jpsrolls
New Scratcher
Registered: 2010-12-09
Posts: 17

Re: Question with multiple answers

[blocks]

<when green flag clicked>
ask "what is your favorite sport" and wait
<if>answer = swimming
<say[ Flipper ]for( 2 )secs>
<if>answer = tennis
<say[Love!  ]for( 2 )secs>
<if>answer = golf
<say[ Fore! ]for(2  )secs>
<if>answer = basketball
<say[ Michael Jordan! ]for( 2 )secs>
<else>
<say[That sounds like a fun sport!  ]for( 2 )secs>
[/blocks]

This works well.  If I use the plain say block, it doesn't.  I wanted to know why.
Thank you,
Judy

Offline

 

#4 2011-02-15 13:34:03

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

Re: Question with multiple answers

jpsrolls wrote:

[blocks]

<when green flag clicked>
ask "what is your favorite sport" and wait
<if>answer = swimming
<say[ Flipper ]for( 2 )secs>
<if>answer = tennis
<say[Love!  ]for( 2 )secs>
<if>answer = golf
<say[ Fore! ]for(2  )secs>
<if>answer = basketball
<say[ Michael Jordan! ]for( 2 )secs>
<else>
<say[That sounds like a fun sport!  ]for( 2 )secs>
[/blocks]

This works well.  If I use the plain say block, it doesn't.  I wanted to know why.
Thank you,
Judy

It doesn't say "That sounds like a fun sport!" after?
I would recommend this code: (untested  tongue )

Code:

when green flag clicked
ask [What is your favorite sport?] and wait
if <(answer) = [swimming]>
   say [swimming (or whatever you want.)]
else
    if <(answer) = [tennis]>
         say [tennis]
    else
         if <(answer) = [golf]>
             say [golf]
         else
              if <(answer) = [basketball]
                   say [basketball]
              else
                   say [That sounds like a fun sport too!]

Last edited by scimonster (2011-02-15 13:34:27)

Offline

 

#5 2011-02-15 17:25:16

jpsrolls
New Scratcher
Registered: 2010-12-09
Posts: 17

Re: Question with multiple answers

This works, thank you!

Judy

Offline

 

#6 2011-02-15 20:37:36

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Question with multiple answers

A way that would work a bit better, assuming you have a lot of sports you'd like to add, would be to create a list of all the sports you want it to recognize, and then a separate list with a corresponding response. Then you would use a script like this:

Code:

When green flag clicked
Ask "What is your favorite sport?" and wait
set [i] to 0
Repeat (length of [sports list])
      change [i] by 1
      if <item [i] of [sports list] = [answer]>
            say (item [i] of [responses])
            end script
      end if
end repeat
say "That sounds like a fun sport!"

http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer