Skip to content

Listen

Chat carries text between objects and avatars nearby or across a region. A script speaks on an integer channel and hears through listeners, which filter what reaches its listen event. Part of the Communications feature.

Concepts

  • Every message is sent on a channel
    • Channel 0 is public chat, seen by people; other channels are only heard by scripts
    • DEBUG_CHANNEL shows in the script warning window
  • Range depends on the function
    • Whisper reaches 10 m, say 20 m and shout 100 m from the speaking prim
    • llRegionSay reaches the whole region, but not on channel 0
    • llRegionSayTo speaks to one avatar or object in the region; on channel 0 to an avatar, only that avatar sees it
    • llOwnerSay sends text only to the owner
  • Messages from scripts are truncated to 1024 bytes
  • A prim cannot hear itself, but can hear other prims in the same object; use link messages inside an object instead
  • llListen opens a listener on a channel, optionally filtered by speaker name, key and exact message, and returns a handle
    • Only messages that match every filter raise listen, with the channel, name, key and message
    • Filters cannot be changed later; a listener on llGetOwner keeps the old owner after a change of owner
  • Listeners cost the region, so keep them few and narrow
    • Pause or resume a listener, or remove it with its handle
    • A script can have 65 listeners open; a state change or reset removes them all
    • Prefer a filtered, non-zero channel to listening on channel 0

Functions and events

llSay(integer channel, string msg)
llRegionSay(integer channel, string msg)
llRegionSayTo(key target, integer channel, string msg)
llOwnerSay(string msg)
integerllListen(integer channel, string name, key id, string msg)
llListenControl(integer handle, integer active)
llListenRemove(integer handle)
eventlisten(integer channel, string name, key id, string msg)

Scripting Details

llOwnerSay(string msg)
Sends the chat message msg privately to the object owner (the owner must be currently in the same region for the message to be received).
llInstantMessage(key agent, string msg)
Sends an instant message containing msg to the agent identified by their key.
llWhisper(integer channel, string msg)
Broadcasts the message msg to all scripts or agents listening on channel within llGetEnv("whisper_range"), which is 10m on most regions. Agents listen on PUBLIC_CHANNEL (0) and DEBUG_CHANNEL (2147483647). All other channels are for script-to-script communication.
llSay(integer channel, string msg)
Broadcasts the message msg to all scripts or agents listening on channel within llGetEnv("chat_range"), which is 20m on most regions. Agents listen on PUBLIC_CHANNEL (0) and DEBUG_CHANNEL (2147483647). All other channels are for script-to-script communication.
llShout(integer channel, string msg)
Broadcasts the message msg to all scripts or agents listening on channel within llGetEnv("shout_range"), which is 100m on most regions. Agents listen on PUBLIC_CHANNEL (0) and DEBUG_CHANNEL (2147483647). All other channels are for script-to-script communication.
llRegionSay(integer channel, string msg)
Broadcasts the message msg to all scripts listening on channel Channel within the region. PUBLIC_CHANNEL (0) cannot be used, so, only scripts can receive the message.
llRegionSayTo(key target, integer channel, string msg)
Sends the message msg on Channel privately to the targeted agent or object (if within the region). If target is an agent and channel is non-zero, the message can also be heard by any attachments worn by the avatar.
integerllListen(integer channel, string name, key id, string msg)
Creates a listener on channel from name and id for msg. Returns an integer listener handle used to control or remove the listener. Empty strings or NULL_KEY filters do not filter on those parameters.
llListenControl(integer handle, integer active)
Enables or disables the listener specified by the integer handle. If active is TRUE, the listener is activated; if FALSE, it is deactivated.
llListenRemove(integer handle)
Completely removes the listener specified by the integer handle.
eventlisten(integer channel, string name, key id, string msg)
Triggered when a chat message matching active llListen filters is received on channel. Passes the sender's name and UUID key id, along with the spoken string msg.

Two objects on a private channel: one sends commands, the other obeys only its owner’s objects.

integer CHANNEL = -731942;
default
{
state_entry()
{
llListen(CHANNEL, "", NULL_KEY, "");
}
listen(integer channel, string name, key id, string message)
{
if (llGetOwnerKey(id) != llGetOwner()) return;
if (message == "on") llSetText("On", <0, 1, 0>, 1);
else if (message == "off") llSetText("", ZERO_VECTOR, 0);
}
}

Constant groups Channel 3ChannelNonPublic 2

See also Feature CommunicationsCategory ChatSL Wiki ListenSL Wiki LSL ChatPlanned Guide: listeners and channels