Difference between revisions of "Listen"

From Second Life Wiki
Jump to navigation Jump to search
Line 8: Line 8:
|constants={{LSL Constants/Chat}}
|constants={{LSL Constants/Chat}}
|spec
|spec
|caveats=*On [[state]] change all listens are released.
|caveats=*On [[state]] change all listens are released (on script reset as well).
*When an object changes owner any listen registered with [[llGetOwner]] will not automatically update itself. The scripter needs to capture this event ([[on_rez]] and [[CHANGED_OWNER]]).
|examples=<pre>
|examples=<pre>
// says beep whenever owner says something in main chat;
// says beep whenever owner says something in main chat;
string owner = "Your Name"; // replace Your Name with your name ;
default
default
{
{
     state_entry()
     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.
         llListen(0, owner, "", "");
         llListen(0, "", llGetOwner(), "");
     }
     }
     listen( integer channel, string name, key id, string message ){
     listen( integer channel, string name, key id, string message ){
         llSay(0,"beep");
         llSay(0,"beep");
    }
    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 has been sold as "original" from in world.
        if(mask & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
}
</pre>
<pre>
// says beep whenever owner says something in main chat;
//Does not use a hard reset to re-register it's listen.
integer handle;
reset()
{
    llListenRemove(handle);
    handle = llListen(0, "", llGetOwner(), "");
}
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.
        reset();
    }
    listen( integer channel, string name, key id, string message ){
        llSay(0,"beep");
    }
    on_rez(integer param)
    {//Triggered when the object is rezed, like after the object had been sold from a vendor
        reset();
    }
    changed(integer mask)
    {//Triggered when the object has been sold as "original" from in world.
        if(mask & CHANGED_OWNER)
        {
            reset();
        }
     }
     }
}
}

Revision as of 01:54, 15 March 2007

Description

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

Trigged by chat, use llListen to enable and filter

• integer channel
• string name
• key id
• string message
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 all listens are released (on script reset as well).
  • When an object changes owner any listen registered with llGetOwner will not automatically update itself. The scripter needs to capture this event (on_rez and CHANGED_OWNER).


Examples

// says beep whenever owner says something in main chat;
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.
        llListen(0, "", llGetOwner(), "");
    }
    listen( integer channel, string name, key id, string message ){
        llSay(0,"beep");
    }
    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 has been sold as "original" from in world.
        if(mask & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
}
// says beep whenever owner says something in main chat;

//Does not use a hard reset to re-register it's listen.
integer handle;

reset()
{
    llListenRemove(handle);
    handle = llListen(0, "", llGetOwner(), "");
}

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.
        reset();
    }
    listen( integer channel, string name, key id, string message ){
        llSay(0,"beep");
    }
    on_rez(integer param)
    {//Triggered when the object is rezed, like after the object had been sold from a vendor
        reset();
    }
    changed(integer mask)
    {//Triggered when the object has been sold as "original" from in world.
        if(mask & CHANGED_OWNER)
        {
            reset();
        }
    }
}

See Also

Functions

•  llListen
•  llListenControl
•  llListenRemove
•  llDialog
•  llWhisper Sends chat limited to 10 meters
•  llSay Sends chat limited to 20 meters
•  llShout Sends chat limited to 100 meters

Deep Notes

Signature

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