llListen

From Second Life Wiki
Revision as of 22:10, 7 August 2008 by Strife Onizuka (talk | contribs) (there is nothing special about using it inside a listen event as opposed to any other scope.)
Jump to navigation Jump to search

Summary

Function: integer llListen( integer channel, string name, key id, string msg );
0.0 Forced Delay
10.0 Energy

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 any valid integer (-2147483648 through 2147483647).
• string name filter for specific prim or avatar name
• key id filter for specific prim/avatar UUID.
• string msg filter for specific chat 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 name is set then the speaker's name must match name exactly. If id is a valid, non-null key then the speaker's key must be equivalent. 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

  • 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.
  • Chat on negative channel numbers cannot be generated by the client except with dialog boxes.
    • This makes it ideal for object2object communications.
    • This may just be an artificial limitation placed on the client and not the underlying protocol.
  • Once a listen is registered it's filters cannot be updated, if the listen is register 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.

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 rezed, like after the object had been sold from a vendor
       llResetScript();//By resetting the script on rez it 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.

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

Deep Notes

Signature

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