Difference between revisions of "LlListen"

From Second Life Wiki
Jump to: navigation, search
(- channels)
(Add llRegionSayTo to "also functions" and notes. Change specification sequence of filtering. Extend notes on handler allocation.)
Line 14: Line 14:
 
|func_footnote=If {{LSLP|msg}}, {{LSLP|name}} or {{LSLP|id}} are blank they are not used to filter incoming messages.
 
|func_footnote=If {{LSLP|msg}}, {{LSLP|name}} or {{LSLP|id}} are blank they are not used to filter incoming messages.
 
If {{LSLP|id}} is an invalid key or a [[NULL_KEY|null key]], it is considered blank.<br/>
 
If {{LSLP|id}} is an invalid key or a [[NULL_KEY|null key]], it is considered blank.<br/>
|spec=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 {{LSLP|channel}}. If {{LSLP|name}} is set then the speaker's name must match {{LSLP|name}} exactly. If {{LSLP|id}} is a valid, non-[[NULL_KEY|null]] key then the speaker's key must be equivalent. If {{LSLP|msg}} is set then the spoken message must match {{LSLP|msg}} exactly.
+
|spec=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 {{LSLP|channel}}. If {{LSLP|id}} is a valid, non-[[NULL_KEY|null]] key then the speaker's key must be equivalent. If {{LSLP|name}} is set then the speaker's name must match {{LSLP|name}} exactly. If {{LSLP|msg}} is set then the spoken message must match {{LSLP|msg}} exactly.
 
|also_functions={{LSL DefineRow||[[llListenRemove]]|Removes a listen}}
 
|also_functions={{LSL DefineRow||[[llListenRemove]]|Removes a listen}}
 
{{LSL DefineRow||[[llListenControl]]|Enables/Disables a listen}}
 
{{LSL DefineRow||[[llListenControl]]|Enables/Disables a listen}}
Line 21: Line 21:
 
{{LSL DefineRow||[[llShout]]|Sends chat limited to 100 meters}}
 
{{LSL DefineRow||[[llShout]]|Sends chat limited to 100 meters}}
 
{{LSL DefineRow||[[llRegionSay]]|Sends chat limited current sim}}
 
{{LSL DefineRow||[[llRegionSay]]|Sends chat limited current sim}}
 +
{{LSL DefineRow||[[llRegionSayTo]]|Sends chat region wide to a specific avatar, or their attachments, or to a rezzed object of known UUID}}
 
|also_events={{LSL DefineRow||[[listen]]|}}
 
|also_events={{LSL DefineRow||[[listen]]|}}
 
|also_tests
 
|also_tests
Line 40: Line 41:
 
:The key/name/message checks only happen at all if those are specified of course.
 
:The key/name/message checks only happen at all if those are specified of course.
 
:
 
:
:So, the most efficient way is [[llRegionSay]] on a rarely used channel.
+
:So, the most efficient communication method is [[llRegionSay]] on a rarely used channel.
*The integer returned can be assigned to a variable (then called a handler) and used to control the listen via [[llListenRemove]] or [[llListenControl]]. These handlers are assigned sequentially starting at 1. If you are using multiple listens in one script, each listen can be assigned its own handler with which to control it.
+
:Nowadays, [[llRegionSayTo]] is to be preferred, where appropriate.
 +
*The integer returned can be assigned to a variable (then called a handler) and used to control the listen via [[llListenRemove]] or [[llListenControl]]. These handlers are assigned sequentially starting at 1. If an llListen is repeated with the exact same filters as a currently active listener, then the same handler number is returned. If an llListen's filters do not match any currently active listener, then the next handler in sequence is allocated (it will not re-allocate a recently removed handler).
 +
*If you are using multiple listens in one script, each listen can be assigned its own handler with which to control it.
 
|caveats=*On [[state]] change or [[llResetScript|script reset]] all listens are removed automatically.
 
|caveats=*On [[state]] change or [[llResetScript|script reset]] all listens are removed automatically.
 
**A state change can be used as a shortcut to releasing listens.
 
**A state change can be used as a shortcut to releasing listens.

Revision as of 13:24, 16 February 2013

Summary

Function: integer llListen( integer channel, string name, key id, string msg );

Sets a callback for msg on channel from name and id.
Returns an integer that can be used to deactivate or remove the listen.

• integer channel input chat channel, any integer value (-2147483648 through 2147483647)
• string name filter for specific prim name or avatar legacy name
• key id filter for specific group, avatar or prim UUID
• string msg filter for specific message

If msg, name or id are blank they are not used to filter incoming messages. If id is an invalid key or a null key, it is considered blank.

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 channel. If id is a valid, non-null key then the speaker's key must be equivalent. If name is set then the speaker's name must match name exactly. If msg is set then the spoken message must match msg exactly.

Channel Constant Description
DEBUG_CHANNEL 0x7FFFFFFF Chat channel reserved for script debugging and error messages, broadcasts to all nearby users.
PUBLIC_CHANNEL 0x0 Chat channel that broadcasts to all nearby users. This channel is sometimes referred to as: open chat, local chat and public chat.

Caveats

  • Messages sent on channel zero[1] and DEBUG_CHANNEL are throttled to a rate of <200/10sec, per region, per owner/user.
    • Once the rate is exceeded, all following messages on channel zero or DEBUG_CHANNEL will be dropped until the send rate is again below 200/10sec for the previous 10 sec. Dropped messages, despite being dropped still count against the limit.
  • 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.
  • The standard SL viewer can only send chat on negative channels through llDialog or llTextBox responses. (Several third party viewers can use these channels from the chat bar.) For maximum compatibility, negative channels are best suited for applications that do not require direct avatar chat.
  • Once a listen is registered its filters cannot be updated, if the listen is registered to llGetOwner, the listen will remain registered to the old owner upon owner change.
    • Owner change can be detected with the changed event.
    • 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, llTextBox or from a linked prim) can be heard if in range.
All Issues ~ Search JIRA for related Bugs

Examples

Trivial example to listen to any chat from the object owner and respond once. To reduce lag and avoid spamming surrounding users, it is vastly preferable to listen on channels other than 0 and to trigger the listen event by chatting on an alternative channel such as '/5 hello'. <lsl>// says beep to owner the first time owner says something in main chat; integer listen_handle;

default {

   state_entry()
   {   // Registers the listen to the owner of the object at the moment of the call.
       // This does not automatically update when the owner changes.
       // Change 0 to another positive number to listen for '/5 hello' style of chat.
       listen_handle = llListen(0, "", llGetOwner(), "");
   }
   listen( integer channel, string name, key id, string message )
   {
       llOwnerSay("beep");
       // Stop listening until script is reset
       llListenRemove(listen_handle);
   }
   on_rez(integer param)
   {   // Triggered when the object is rezzed, like after the object has been sold from a vendor
       llResetScript();//By resetting the script on rez forces the listen to re-register.
   }
   changed(integer mask)
   {   // Triggered when the object containing this script changes owner.
       if(mask & CHANGED_OWNER)
       {
           llResetScript();
       }
   }
}</lsl>

Notes

  • Avoid channel 0 and set name or id where possible to avoid Lag. llListen(0,"","","") can be extremely laggy as it listens to all chat from everyone in chat range and so it should be avoided at all cost.
  • In November 2007, Kelly Linden offered this explanation to help scripters plan listeners more efficiently:
  1. Chat that is said gets added to a history.
  2. A script that is running and has a listen event will ask the history for a chat message during its slice of run time.
  3. 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
    • key
    • name
    • message
  4. If a message is found then a listen event is added to the event queue.
The key/name/message 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 handler) and used to control the listen via llListenRemove or llListenControl. These handlers are assigned sequentially starting at 1. If an llListen is repeated with the exact same filters as a currently active listener, then the same handler number is returned. If an llListen's filters do not match any currently active listener, then the next handler in sequence is allocated (it will not re-allocate a recently removed handler).
  • If you are using multiple listens in one script, each listen can be assigned its own handler with which to control it.

See Also

Events

•  listen

Functions

•  llListenRemove Removes a listen
•  llListenControl Enables/Disables a listen
•  llWhisper Sends chat limited to 10 meters
•  llSay Sends chat limited to 20 meters
•  llShout Sends chat limited to 100 meters
•  llRegionSay Sends chat limited current sim
•  llRegionSayTo Sends chat region wide to a specific avatar, or their attachments, or to a rezzed object of known UUID

Deep Notes

All Issues

~ Search JIRA for related Issues
   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)
   llTargetSay() - region-wide direct communication

Footnotes

  1. ^ Channel zero is also known as: PUBLIC_CHANNEL, open chat, local chat and public chat

Signature

function integer llListen( integer channel, string name, key id, string msg );