Skip to content
lsl.devlsl.devLSL Dev

Listen

Looking for the current API? Open the listen reference →

Wiki description

Triggered by chat, use llListen to enable and filter

Specification

Channel Constant Description
DEBUG_CHANNEL0x7FFFFFFFChat channel reserved for script debugging and error messages, broadcasts to all nearby users.
PUBLIC_CHANNEL0x0Chat 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

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

Shared wiki helpers

The original page also injects shared parameter notes, caveats or issue information through these helpers. Their conditional MediaWiki logic is not reproduced here; inspect the preserved helper source for additional material.

Template:LSL Function/uuid

Original shared helper source (conditional wiki logic is not evaluated)
<noinclude>{{Multi-lang|category=LSL}}</noinclude>{{LSL Injection Test}}{{#if:

{{#vardefine:p_{{{1|none}}}_desc|{{#if:{{{pd|}}}|{{{pd|}}}&#32;}}{{#if:{{{group|1}}}|{{LSLGC|Group|group}},&#32;}}{{LSLGC|Avatar|avatar}} or {{#if:{{{object|}}}|[[object]]|[[prim]]}} {{HoverLink|UUID|Universally Unique Identifier}} {{#if:{{{sim|}}}|that is in the same [[region]] {{#switch:{{{sim|}}}|*=|#default = &#32;{{{sim|}}}}}
}}}}

{{#vardefine:p_{{{1|none}}}_hover|{{#if:{{{ph|}}}|{{{ph|}}}&#32;|{{#if:{{{pd|}}}|{{{pd|}}}&#32;}}}}{{#if:{{{group|1}}}|group,&#32;}}avatar or {{#if:{{{object|}}}|object|prim}} UUID {{#if:{{{sim|}}}|that is in the same region {{#switch:{{{sim|}}}|*=|#default = &#32;{{{sim|}}}}}
}}}}

<includeonly>
{{#ifeq:{{#var:article-type}}|event||{{#if:{{#pos:{{#var:moded}}|r}}{{#pos:{{#var:moded}}|u}}||{{#vardefine:hidden-text|{{#var:hidden-text}}
{{LSLC|Avatar/As A Parameter}}
}}}}}}
</includeonly>

}}<noinclude>
{| {{Prettytable}}
|-{{Hl2}}
!var
!value
|-
|desc
|{{#var:p_{{{1|none}}}_desc}}
|-
|hover
|{{#var:p_{{{1|none}}}_hover}}
|}
</noinclude>

Template:Issues/SVC-92

Original shared helper source (conditional wiki logic is not evaluated)
{{Issues|SVC-92|'''llTargetSay'''() - region-wide direct communication|type=nf|status=pub|resolution=fixed}}
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.