integer llListen(integer channel,// Chat channel (any 32-bit signed integer value) to listen on. Exact range is -2147483648 to 2147483647. Values: Channelstring name,// Specific prim name or agent legacy name to filter by (or empty string for no filter).key id,// Specific agent or prim UUID to filter by (orNULL_KEYfor no filter).string msg// Specific chat message string to filter by (or empty string for no filter).
);- Returns
integer- Energy
- 10
Sets a handle for msg on channel from name and id.
If msg, name or id are blank (i.e. "") they are not used to filter incoming messages.
If id is an invalid key or assigned the value NULL_KEY, it is considered blank as well.
Returns an integer that can be used to deactivate or remove the listen.
integer result = llListen(0, "", NULL_KEY, "");Specification
Section titled “Specification”For the listen event to be triggered it must first match the criteria set forth by the filters; only when all the criteria have been met is a listen event generated. First the message must have been transmitted on channel. If id is both a valid key and not a null key, then the speaker’s key must be equivalent1 to id. If name is set, then the speaker’s legacy name must match name exactly (case sensitive). If msg is set, then the spoken message must match msg exactly (case sensitive).
Caveats
Section titled “Caveats”- On state change or script reset all listens are removed automatically.
- A state change can be used as a shortcut to releasing listens.
- Only 65 listens can simultaneously be open in any single script.
- If this number is exceeded Script run-time error and Too Many Listens errors occur.
- For some time, the official SL viewer and several third-party viewers can use negative channels from the chat bar directly just as any other non-zero channel. Formerly, the standard SL viewer could only send chat on negative channels through
llDialogorllTextBoxresponses, meaning negative channels were best suited for applications that did not require direct avatar chat. - Be aware that if you mistakenly use an integer literal bigger than the maximum or smaller than the minimum, LSL will treat it as -1, without giving any compilation error. This means that all scripts listening to an out-of-range integer will be listening to channel -1 instead, or if the number has a minus sign in front, to channel 1. A safe rule is to never use more than 9 digits. If the channel number comes from a conversion from float (for example from
llFrand), if the float is out of range for an integer, it will be converted to the number -2147483648 regardless of its sign or value. - Messages sent by script on positive and negative channels are truncated to 1024 bytes. Messages sent by chat on positive channels are truncated to 1023 bytes. Messages sent by chat from negative channels are truncated to 254 bytes.
- Once a
listenis registered its filters cannot be updated, if the listen is registered tollGetOwner, the listen will remain registered to the previous owner upon owner change. - Owner change can be detected with the
changedevent. - To work around this the old listen will need to be closed and a new one opened for the new owner.
- A prim cannot hear/listen to chat it generates. It can, however, hear a linked prim.
- Chat indirectly generated (as a result of
llDialog,llTextBoxor from a linked prim) can be heard if in range.
Examples
Section titled “Examples”Trivial example to listen to any chat from the object owner and respond once.
| Single listen handle |
|---|
|
| Two listen handles |
|---|
|
-
Avoid channel zero (
PUBLIC_CHANNEL) and set name or id where possible to avoid lag.llListen(0, "", NULL_KEY,"")can be laggy as it listens to all chat from everyone in chat range and so should be avoided. -
In November 2007, Kelly Linden offered this explanation to help scripters plan listeners more efficiently:
:#Chat that is said gets added to a history.
:#A script that is running and has a listen event will ask the history for a chat message during its slice of run time.
:# When the script asks the history for a chat message the checks are done in this order:
:#* channel
:#* self chat (prims can’t hear themselves)
:#* distance/RegionSay
:#* id
:#* name
:#* msg
:# If a msg is found then a listen event is added to the event queue.
:
:The id/name/msg checks only happen at all if those are specified of course.
:
:So, the most efficient communication method is llRegionSay on a rarely used channel.
:Nowadays, llRegionSayTo is to be preferred, where appropriate.
- The integer returned can be assigned to a variable (then called a handle) and used to control the listen via
llListenRemoveorllListenControl. These handles are assigned sequentially starting at+1through to+2,147,483,647, going beyond which, according to Simon Linden, will roll the returned integer over to−2,147,483,648, when positive incrementation resumes. If anllListenis repeated with the exact same filters as a currently active listener, then the same handle number is returned. If an llListen’s filters do not match any currently active listener, then the next handle in sequence is allocated (it will not re-allocate a recently removed handle). - If you are using multiple listens in one script, each listen can be assigned its own handle with which to control it.
- Scripts can listen to and speak on
DEBUG_CHANNEL. Script errors generated by the server are broadcast the same distance asllSay, but any chat command can be used to speak onDEBUG_CHANNEL. - Messages received on
DEBUG_CHANNELin the viewer are hidden unless the message is sent by an object owned by the current user. - Users may just see script errors as the hovering ‘script error’ icon depending on their viewer settings, and in any case will be able to read errors regardless of whether they are errors thrown by the scripting engine or your own debugging messages.
Known issues
Section titled “Known issues”From the issue templates included by the wiki article:
- SVC-3170 (bug): Listeners in child prims get positioned at root prim position first, then switch to child prim position after re-rez (resulting in wrong listener / whisper radius)
- SVC-92 (nf): llTargetSay() - region-wide direct communication
- BUG-3291 (bug): llListen in linked objects is listening at root instead of linked object local position *after re-rezzing the linkset*
See also
Section titled “See also”Functions
Section titled “Functions”llListenRemove— Removes a listenllListenControl— Enables/Disables a listenllWhisper— Sends chat limited to 10 metersllSay— Sends chat limited to 20 metersllShout— Sends chat limited to 100 metersllRegionSay— Sends chat limited current simllRegionSayTo— Sends chat region wide to a specific avatar, or their attachments, or to a rezzed object of known UUID
Events
Section titled “Events”Original wiki source
Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.