Skip to content
lsl.devlsl.devLSL Dev

LlMessageLinked

Looking for the current API? Open the llMessageLinked reference →

Wiki description

The purpose of this function is to allow scripts in the same object to communicate. It triggers a link_message event with the same parameters num, str, and id in all scripts in the prim(s) described by link.

Function guidance

You can use id as a second string fieldIn LSL the key type is implemented as a string (but with different operators and restrictions). Typecasting between string and key types has no effect on the data contained.. The sizes of str and id are only limited by available script memory.

Caveats

  • A script can hear its own linked messages if link targets the prim it is inThere are four ways for a script to target itself: by precise link number, LINK_THIS, LINK_SET and LINK_ALL_CHILDREN (if the prim is a child prim).. This creates the possibility of an infinite loop (a bad thing); be very careful about how messages are handled and passed along.
  • Messages sent via llMessageLinked to a script that is sleeping, delayed, or lagged, are queued until the end of the delay. The event queue can hold 64 events.
    • If an event is received and the queue is full the event is silently dropped.
    • Avoid sending link_messages to large numbers of scripts simultaneously as it can cause lag spike. This most often happens when using the multi-prim LINK_* flags and can cause script execution to slow or halts.
    • Avoid sending link_messages to a target faster than they can be handled. Doing so risks filling the event queue and subsequent messages being silently discarded.
  • When a script state changes, all pending events are deleted, including queued link_messages.
  • If link is an invalid link number then the function silently fails.
  • If str & id exceed the available memory of a script that catches the resulting link_message event, that script will crash with a Stack-Heap Collision.

Examples

default
{
    // assumptions  // object name: LSLWiki // script name: _lslwiki
    state_entry()
    {
        llMessageLinked(LINK_THIS, 0, llGetScriptName(), "");
    }

    link_message(integer sender_num, integer num, string msg, key id)
    {
        llOwnerSay(msg);
        // the owner of object LSLWiki will hear
        // LSLWiki:_lslwiki
    }
}

Infinite Loop

Message_Control(integer l, integer n) // Message_Total_Lack_Of_Control
{
    integer r = (++n); // Increment the value of n.
    llMessageLinked( l, r, "", ""); // Send the result to l
}

default
{
    state_entry()
    {
        Message_Control(LINK_SET, 0); // Tell all the scripts in the object that we have state_entered.
    }
    link_message(integer Sender, integer Number, string String, key Key) // This script is in the object too.
    {
        Message_Control(Sender, Number); // No filtering condition exists.
        llOwnerSay(((string)Number)); // Look at all the pretty numbers!
    }
}

Helper functions

default
{
    // Quick and dirty debugging link_messages
    link_message(integer sender_num, integer num, string msg, key id)
    {
        llSay(DEBUG_CHANNEL, llList2CSV([sender_num, num, msg, id]));
    }
}
// This is just an example script, you shouldn't handle link message within single script this way.

default
{
    // To propagate an unlimted number of arguments of any type.
    // Presumed, the separator string isn't used in any source string!
    state_entry()
    {
        list my_list = [1, 2.0, "a string", <1, 2, 3>, <1, 2, 3, 4>, llGetOwner()];
        string list_parameter = llDumpList2String(my_list, "|");    // Convert the list to a string
        llMessageLinked(LINK_THIS, 0, list_parameter, "");
    }

    link_message(integer sender_num, integer num, string list_argument, key id)
    {
        list re_list = llParseString2List(list_argument, ["|"], []);    // Parse the string back to a list
    }
}

Notes

  • Using llMessageLinked in a single prim object allows developers to mitigate some LSL limits by breaking up functionality between cooperating scripts and synchronizing actions. When you do this, be extremely careful not to create infinite loops as mentioned above.
  • Estimated .25 to .50 delay between receiving and sending of llMessageLinked has been observed by some users
  • Some users have noted occasional failures of linked messages when sending a message to a large number of receiving scripts in different prims using LINK_SET, LINK_ALL_OTHERS, & LINK_ALL_CHILDREN. If you encounter this problem, a workaround is to place all child prim scripts in a single prim, using targeted functions like llSetLinkPrimitiveParams to modify the prim in which the script previously resided. -- Void Singer
  • This function seems to create a lower lag level then llListen since it does not need a listener.

See also: events

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/link

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

{{#vardefine:header|{{#var:header}}
{{#switch:{{#if:{{{nc|}}}|Template|{{NAMESPACE}}}}|Template=|User=|}}}}

<includeonly>
{{#ifeq:{{#var:article-type}}|event||{{#if:{{#pos:{{#var:moded}}|r}}{{#pos:{{#var:moded}}|u}}||{{#vardefine:hidden-text|{{#var:hidden-text}}
{{LSLC|Link{{#var:lang}}}}{{#if:{{{mode|}}}|{{LSLC|Link/{{{mode}}}{{#var:lang}}}}}}
}}}}}}
</includeonly>

{{#if:{{{nlf|}}}{{{noconst|}}}{{#var:link_constants}}||
{{#vardefine:constants_nb|
{{{!}} style={{{ostyle|}}}
{{!}}- valign="top"
{{!}}
{{{!}} {{Prettytable|style=margin-top:0;}}
{{!}}-{{Hl2}}
! colspan="2" {{!}}Flag
!Description
{{!}}-
{{!}} {{LSL Const|LINK_ROOT|integer|1|c={{{verb|refers to}}} the root prim in a multi-prim linked set}}
{{!}} {{#var:value}}
{{!}} {{{verb|refers to}}} the [[Link#Root_Prim|root]] prim in a multi-prim linked set{{Footnote|handle=LINK_ROOT|LINK_ROOT does not work on single [[prim]] [[object|objects]]. Unless there is an avatar sitting on the [[object]].}}
{{#if:{{{nogroup|}}}||{{!}}-
{{!}} {{LSL Const|LINK_SET|integer|-1|c={{{verb|refers to}}} all prims}}
{{!}} {{#var:value}}
{{!}} {{#var:comment}}
{{!}}-
{{!}} {{LSL Const|LINK_ALL_OTHERS|integer|-2|c={{{verb|refers to}}} all other prims}}
{{!}} {{#var:value}}
{{!}} {{#var:comment}}}}
{{!}}}
{{!}}
{{{!}} {{Prettytable|style=margin-top:0;}}
{{!}}-{{Hl2}}
! colspan="2" {{!}}Flag
!Description
{{!}}-
{{#if:{{{nogroup|}}}||{{!}} {{LSL Const|LINK_ALL_CHILDREN|integer|-3|c={{{verb|refers to}}} all children, (everything but the root)}}
{{!}} {{#var:value}}
{{!}} {{{verb|refers to}}} all children, (everything but the [[Link#Root_Prim|root]])}}
{{!}}-
{{!}} {{LSL Const|LINK_THIS|integer|-4|c={{{verb|refers to}}} the prim the script is in}}
{{!}} {{#var:value}}
{{!}} {{{verb|refers to}}} the [[prim]] the [[script]] is in
{{!}}}
{{!}}}
{{#var:constants_nb}}}}
{{#vardefine:link_constants|*}}
}}

{{#vardefine:p_{{{1|}}}_desc|[[Link]] number ({{#if:{{{nounlinked|}}}||0: {{HoverText|unlinked|When an object is made up of only one prim, and there are no avatars seated upon it, the link number of the (root) prim is zero.}},&#32;}}1: {{HoverText|[[Link#Root_Prim|root]] prim|When an object is made up of multiple prims or there is an avatar seated upon the object, the root prim's link number is one}}, &gt;1: child prims{{#if:{{{noavatar|}}}||&#32;and {{HoverText|seated avatars|Avatars sitting on objects are assigned link numbers. They are always greater than prim link numbers.}}}}) {{#if:{{{nlf|}}}||or a <code>LINK_*</code> [[flag]]}}{{{2|}}}&#32;}}
{{#vardefine:p_{{{1|}}}_hover|Link number ({{#if:{{{nounlinked|}}}||0: unlinked,&#32;}}1: root prim, &gt;1: child prims{{#if:{{{noavatar|}}}||&#32;and seated avatars}}) {{#if:{{{nlf|}}}||or a LINK_* flag}}{{#if:{{{3|}}}|{{{3|}}}|{{{2|}}}}}&#32;}}

{{#if:{{{nocaveats|}}}||{{#if:{{{noavatar|}}}|
{{#vardefine:caveats|
*{{LSLP|{{{1|}}}}} cannot be a {{HoverText|seated avatar|Avatars sitting on objects are assigned link numbers. They are always greater than link numbers of prims.}}.
{{#var:caveats}}}}
}}{{#if:{{{nogroup|}}}|
{{#vardefine:caveats|
*{{LSLP|{{{1|}}}}} needs to be either an actual [[llGetLinkNumber|link number]] or a link constants that equate to a single prim, such as [[LINK_ROOT]] and [[LINK_THIS]].
**[[LINK_SET]], [[LINK_ALL_CHILDREN]] and [[LINK_ALL_OTHERS]] will not work.
{{#var:caveats}}}}
}}}}

{{#if:{{#var:link_stuff}}||
{{#vardefine:link_stuff|*}}
{{#vardefine:notes|
<h3>Link Numbers</h3>
Each prim that makes up an [[object]] has an address, a link number. To access a specific [[prim]] in the [[object]], the [[prim]]'s link number must be known. In addition to [[prim|prims]] having link numbers, avatars seated upon the [[object]] do as well.
* If an [[object]] consists of only one [[prim]], and there are no avatars seated upon it, the ([[Link#Root_Prim|root]]) [[prim]]'s link number is zero.
* However, if the [[object]] is made up of multiple prims or there is an avatar seated upon the [[object]], the [[Link#Root_Prim|root]] [[prim]]'s link number is one.

When an avatar sits on an [[object]], it is added to the end of the link set and will have the largest link number. In addition to this, while an avatar is seated upon an object, the object is unable to link or unlink prims without [[llUnSit|unseating]] all avatars first.
<h4>Counting Prims & Avatars</h4>
There are two functions of interest when trying to find the number of prims and avatars on an object.
* <code>[[llGetNumberOfPrims]]()</code> - Returns the number of [[prim|prims]] and seated avatars.
* <code>[[llGetObjectPrimCount]]([[llGetKey]]())</code> - Returns only the number of [[prim|prims]] in the [[object]] but will return zero for attachments.

<syntaxhighlight lang="lsl2">integer GetPrimCount() { //always returns only the number of prims
    if(llGetAttached())//Is it attached?
        return llGetNumberOfPrims();//returns avatars and prims but attachments can't be sat on.
    return llGetObjectPrimCount(llGetKey());//returns only prims but won't work on attachments.
}</syntaxhighlight>See [[llGetNumberOfPrims]] for more about counting prims and avatars.

<h4>Errata</h4>
If a script located in a [[Link#Child_Prim|child]] prim erroneously attempts to access link 0, it will get or set the property of the linkset's [[Link#Root_Prim|root]] prim.  This bug ({{jira|BUG-5049}}) is preserved for broken legacy scripts. {{PBR}}
{{#var:notes}}
}}

{{#vardefine:also_functions|{{#var:also_functions}}
{{LSL DefineRow||[[llGetLinkNumber]]|Returns the link number of the [[prim]] the script is in.}}}}
}}

}}<noinclude>
{| {{Prettytable}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|p_{{{1|}}}_desc}}
|-
{{VarPairTable|also_functions}}
|-
{{VarPair|constants_nb}}
|-
{{VarPair|notes}}
|}
</noinclude>
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.