Speaking and Listening
Spoken communication in Second Life occurs over channels. When avatars converse with each other, they are communicating on channel 0. Anything that is said on channel 0 near an avatar will be displayed to the screen. Figure 6.1 shows an avatar hearing communication around him.
Figure 6.1: Conversation on Channel 0

Messages on other channels are not displayed to avatars. These other channels are reserved for objects and there is no easy way for an avatar to listen on one of these channels. However, avatars can easily talk on other channels. By prefixing what the avatar is saying with a slash, and then a number, the avatar can speak on other channels. For example, the following would say “Hello” on channel 1.
/1Hello
Many objects use this as a means of receiving commands from the object's owner. The object could have just as easily accepted a command on channel 0; however, by accepting it over channel 1, the command will not be broadcast to other nearby avatars.
Objects in Second Life can communicate in many of the same ways that avatars communicate. Objects can listen to conversations going on around them. Objects can also speak and participate in those conversations. Objects can also send instant messages to avatars. However, instant messages between an avatar and an object are one-way. An avatar cannot send an instant message back to an object.
The following script demonstrates how an object can listen to conversations going on around it. The object will wait for someone to say either “hello” or “goodbye”. Once the object detects either of these words, the object says an appropriate greeting to the avatar that spoke to the object. This can be seen in Listing 6.1.
Listing 6.1: Say Hello
integer CHANNEL = 0;
default
{
state_entry()
{
llListen(CHANNEL, "", NULL_KEY, "");
}
listen(integer channel, string name, key id,
string message)
{
if( llToLower(message) == "hello" )
{
llSay(CHANNEL,"Hello " + name );
}
else if( llToLower(message) == "goodbye" )
{
llSay(CHANNEL,"Goodbye " + name );
}
}
}
For an object to begin listening, the object must call the llListen function. This function specifies what channel the object would like to listen on. The above script calls the llListen function in the state_entry event handler. The script specifies that it would like to listen to the channel specified by the CHANNEL variable. The Linden Scripting Language does not have user defined constants. As a result, the above declaration of CHANNEL is as close as we can come to a constant.
Channel zero is the normal conversation channel in Second Life. All communication between avatars is on channel zero. Therefore, by requesting to listen on channel zero, the object will be notified anytime something is said near to the object.
The above script contains a listen event handler. This event handler is called each time something is said near the object. The object checks for either “hello” or “goodbye”. Because the strings are converted to lower case, the user could also enter “Hello” or any mixture of upper and lower case characters. The script responds with a greeting directed to the avatar's name. The avatar's name was passed in as a parameter named name.
The llSay function is used when a script wants to say something. The above calls to llSay use channel zero. However, objects will often want to communicate with each other, and not allow nearby avatars to listen in. To do this, the script should specify a channel other than zero. Many recipes in this book will communicate on channels other than zero.
In addition to llSay, there are two other functions that allow a script to talk. The only difference between the three communication functions is the distance they cover. Table 1.1 summarizes the communication functions.
Table 1.1: Communication Distances
| Communication Function | Distance |
|---|---|
| llWhisper | 10m |
| llSay | 20m |
| llShout | 100m |
There is also a fourth communication function, that has unlimited range. The llInstantMessage function allows an instant message to be sent to the specified avatar. This can be seen in Listing 6.2.
Listing 6.2: Instant Message
default
{
touch_start(integer total_num)
{
// get the key of the objects owner.
key owner=llGetOwner();
llInstantMessage(owner,llKey2Name(owner)+", "
+ (string)total_num +" Avatar(s) touched me!");
}
}
The above script will send a message to the object's owner every time the object is touched. It is also possible to send a message to the object's owner by using the llOwnerSay function. However, llOwnerSay does not have the unlimited distance of a llInstantMessage function call.
It is also possible to communicate to the entire region. The command llRegionSay will send a message to objects across the entire region. The llRegionSay function cannot be used on channel 0. Therefore, llRegionSay is only useful for communications between objects.












