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

#1 2012-03-02 05:39:43

wjack2010
Scratcher
Registered: 2010-06-28
Posts: 100+

How to make it respond to a message

Hello,

I'm making a computer VS human chat kind of thing, where for example human as in me, says "What's your name?" the computer replies "Bob"

How would I go about doing this?

Offline

 

#2 2012-03-02 07:55:06

DaScratcher101
Scratcher
Registered: 2012-02-16
Posts: 41

Re: How to make it respond to a message

If I receive What's you name
Say bob

Offline

 

#3 2012-03-02 08:42:36

wei2912
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: How to make it respond to a message

I have one here at http://scratch.mit.edu/projects/wei2912/1238700, you can take a look at its scripts.


Waiting for Scratch 2.0...

Offline

 

#4 2012-03-02 11:49:54

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: How to make it respond to a message

Using your example:

When gf clicked
forever
ask [What would you like to ask?] and wait
if <(answer) = [What's your name?]>
say [Bob] for [2] secs
end
end
If you want to have it answering lots of questions then one solution would be to nest the if else blocks:

When gf clicked
forever
ask [What would you like to ask?] and wait
if <(answer) = [What's your name?]>
say [Bob] for [2] secs
else
if <(answer) = [Are you real?]>
say [I think, therefore I am.] for [2] secs
else
if <(answer) = [What are you?]>
say [Can't you tell?] for [2] secs
else

end
end
end
end
A more elegant solution would be to use two lists. One called questions and one called  answers.

Then have a script something like this:

When gf clicked
forever
ask [What would you like to ask?] and wait
set (counter) to [0]
repeat until <<(answer) = <item (counter) of [Questions v]>> or <(counter) = <length of [Questions v]>>>
change [counter v] by [1]
if <(answer) = <item (counter) of [Questions v]>>
say <item (counter) of [Answers v]> for [2] secs
end
end

end

Last edited by Smozzick (2012-03-02 11:57:38)


http://i50.tinypic.com/ded8m.png

Offline

 

#5 2012-03-02 11:59:21

wjack2010
Scratcher
Registered: 2010-06-28
Posts: 100+

Re: How to make it respond to a message

Smozzick wrote:

Using your example:

When gf clicked
forever
ask [What would you like to ask?] and wait
if <(answer) = [What's your name?]>
say [Bob] for [2] secs
end
end
If you want to have it answering lots of questions then one solution would be to nest the if else blocks:

When gf clicked
forever
ask [What would you like to ask?] and wait
if <(answer) = [What's your name?]>
say [Bob] for [2] secs
else
if <(answer) = [Are you real?]>
say [I think, therefore I am.] for [2] secs
else
if <(answer) = [What are you?]>
say [Can't you tell?] for [2] secs
else

end
end
end
end
A more elegant solution would be to use two lists. One called questions and one called  answers.

Then have a script something like this:

When gf clicked
forever
ask [What would you like to ask?] and wait
set (counter) to [0]
repeat until <<(answer) = <item (counter) of [Questions v]>> or <(counter) = <length of [Questions v]>>>
change [counter v] by [1]
if <(answer) = <item (counter) of [Questions v]>>
say <item (counter) of [Answers v]> for [2] secs
end
end

end

Thank you for those  smile

Offline

 

#6 2012-03-02 15:49:31

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: How to make it respond to a message

No problem, hope they help ^^


http://i50.tinypic.com/ded8m.png

Offline

 

Board footer