Difference between revisions of "Listen"

From Second Life Wiki
Jump to navigation Jump to search
(Added llOwnerSay to 'Also')
m (Replaced <source> with <syntaxhighlight>)
 
(21 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{LSL_Event|event_id=12|event_delay
{{LSL_Event|event_id=12|event_delay
|inject-2={{LSL Function/uuid|id|group=}}{{Issues/SVC-92}}
|event=listen
|event=listen
|p1_type=integer|p1_name=channel|p1_desc
|p1_type=integer|p1_name=channel|p1_desc=channel that the message appeared on.
|p2_type=string|p2_name=name|p2_desc
|p2_type=string|p2_name=name|p2_desc=prim name or avatar {{LSLGC|Legacy Name}}
|p3_type=key|p3_name=id|p3_desc
|p3_type=key|p3_name=id|p3_desc
|p4_type=string|p4_name=message|p4_desc
|p4_type=string|p4_name=message|p4_desc=text spoken
|event_desc=Trigged by chat, use {{LSLG|llListen}} to enable and filter
|event_desc=Triggered by chat, use [[llListen]] to enable and filter
|constants={{LSL Constants/Chat}}
|constants={{LSL Constants/Chat}}
|spec
|spec
|caveats=*On [[state]] change or [[llResetScript|script reset]] all listens are [[llListenRemove|closed]] automaticaly.
|caveats=*On [[state]] change or [[llResetScript|script reset]] all listens are [[llListenRemove|closed]] automatically.
*When an object changes owner any listen registered with [[llGetOwner]] will not automatically update itself until the script is reset. The scripter can catch this scenario per the example below.
*When an object changes owner any listen registered with [[llGetOwner]] will not automatically update itself until the script is reset. The scripter can catch this scenario per the example below.
*If a message satisfies the filters of multiple [[llListen]]s registered by the script, only one event will be raised.
*A prim cannot hear/listen to chat it generates.
*The location of the listen is not at the listening prim's location but at the root prim's location. This is to deter people using child prims for spying over parcel boundaries. {{LSLGC|Chat|Chat generating functions}} on the other hand generate chat at the calling prim's location (and not at the root prim's location).
*The above is not true for chat generated by avatars sitting on the same object as the listening prim.
|examples=
|examples=
{{LSL Tip|Please make sure that you close open listeners where possible. You'll make the Second Life experience so much better when paying attention to details here.}}
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'.
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'.
<pre>
<syntaxhighlight lang="lsl2">
// says beep to owner the first time owner says something in main chat;
// says beep to owner the first time owner says something in main chat;
integer listen_handle;
integer listen_handle;
Line 23: Line 29:
         listen_handle = llListen(0, "", llGetOwner(), "");
         listen_handle = llListen(0, "", llGetOwner(), "");
     }
     }
     listen( integer channel, string name, key id, string message )
     listen( integer channel, string name, key id, string message )
     {
     {
Line 29: Line 36:
         llListenRemove(listen_handle);
         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)
     changed(integer mask)
     {  //Triggered when the object containing this script changes owner.
     {  //Triggered when the object containing this script changes owner.
         if(mask & CHANGED_OWNER)
         if(mask & CHANGED_OWNER)
         {
         {
             llResetScript();
             llResetScript();   // This will ensure the script listens to the new owner, and doesn't continue listening to the creator.
         }
         }
     }
     }
}
}</syntaxhighlight>
</pre>


|helpers
|helpers
Line 51: Line 54:
{{LSL DefineRow||[[llListenRemove]]|}}
{{LSL DefineRow||[[llListenRemove]]|}}
{{LSL DefineRow||[[llDialog]]|}}
{{LSL DefineRow||[[llDialog]]|}}
{{LSL DefineRow||[[llOwnerSay]]|Sends chat to the owner only to avoid spamming the[[PUBLIC_CHANNEL]]}}
{{LSL DefineRow||[[llOwnerSay]]|Sends chat to the owner only to avoid spamming the [[PUBLIC_CHANNEL]]}}
{{LSL DefineRow||[[llWhisper]]|Sends chat limited to 10 meters}}
{{LSL DefineRow||[[llWhisper]]|Sends chat limited to 10 meters}}
{{LSL DefineRow||[[llSay]]|Sends chat limited to 20 meters}}
{{LSL DefineRow||[[llSay]]|Sends chat limited to 20 meters}}

Latest revision as of 15:46, 9 February 2023

Description

Event: listen( integer channel, string name, key id, string message ){ ; }

Triggered by chat, use llListen to enable and filter

• integer channel channel that the message appeared on.
• string name prim name or avatar Legacy Name
• key id avatar or prim UUID
• string message text spoken
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 closed automatically.
  • When an object changes owner any listen registered with llGetOwner will not automatically update itself until the script is reset. The scripter can catch this scenario per the example below.
  • If a message satisfies the filters of multiple llListens registered by the script, only one event will be raised.
  • A prim cannot hear/listen to chat it generates.
  • The location of the listen is not at the listening prim's location but at the root prim's location. This is to deter people using child prims for spying over parcel boundaries. Chat generating functions on the other hand generate chat at the calling prim's location (and not at the root prim's location).
  • The above is not true for chat generated by avatars sitting on the same object as the listening prim.


Examples

KBcaution.png Important: Please make sure that you close open listeners where possible. You'll make the Second Life experience so much better when paying attention to details here.

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'.

// 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);
    }

    changed(integer mask)
    {   //Triggered when the object containing this script changes owner.
        if(mask & CHANGED_OWNER)
        {
            llResetScript();   // This will ensure the script listens to the new owner, and doesn't continue listening to the creator.
        }
    }
}

See Also

Functions

•  llListen
•  llListenControl
•  llListenRemove
•  llDialog
•  llOwnerSay Sends chat to the owner only to avoid spamming the PUBLIC_CHANNEL
•  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 to region

Deep Notes

Issues

All Issues

~ Search JIRA for related Issues
   llTargetSay() - region-wide direct communication

Signature

event void listen( integer channel, string name, key id, string message );