Difference between revisions of "LlMessageLinked"

From Second Life Wiki
Jump to navigation Jump to search
m (Copy editing, clarification)
Line 27: Line 27:
</pre>
</pre>
|helpers=<pre>
|helpers=<pre>
//Quick and dirty debugging link_messages
//
default
default
{//Quick and dirty debugging link_messages
{
     link_message(integer sender_num, integer num, string msg, key id) {
     link_message(integer sender_num, integer num, string msg, key id) {
         llSay(DEBUG_CHANNEL, llList2CSV([sender_num, num, msg, id]));
         llSay(DEBUG_CHANNEL, llList2CSV([sender_num, num, msg, id]));
     }
     }
}
</pre>
<pre>
// To propagate an unlimted number of arguments of any type.
// Presumed, the separator string isn't used in any source string!
//
default{ 
    state_entry() {   
        list my_list = [1, 2.0, "a string", <1, 2, 3>, <1, 2, 3, 4>, llGetOwner()]; 
        string list_parameter = llDumpList2String(my_list, "|"); // Typecast list to a string
        llMessageLinked(LINK_THIS, 0, list_parameter, NULL_KEY)
    }
    link_message(integer sender_num, integer num, string list_argument, key id) {
        list re_list = llParseString2List(list_argument, ["|"], [""]); // Typecast string back to a list
    }   
}
}
</pre>
</pre>

Revision as of 01:24, 7 September 2007

Summary

Function: llMessageLinked( integer linknum, integer num, string str, key id );
0.0 Forced Delay
10.0 Energy

Triggers a link_message event with the parameters num, str, and id in the group or link linknum.

• integer linknum Link number or a LINK_* flag.
• integer num
• string str
• key id

You can use id as a second string field (in LSL the key type is implemented as a string with just custom operators). Typecasting between string and key types has no effect on the data contained.

Flag Description
LINK_ROOT 1 refers to the root prim in a multi-prim linked set[1]
LINK_SET -1 refers to all prims
LINK_ALL_OTHERS -2 refers to all other prims
Flag Description
LINK_ALL_CHILDREN -3 refers to all children, (everything but the root)
LINK_THIS -4 refers to the prim the script is in

Caveats

  • A script can hear its own linked messages if linknum is set to LINK_SET or LINK_THIS. This creates the possibility of an infinite loop (a bad thing); be very careful about how messages are handled and passed along.

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
    }    
}

Useful Snippets

//Quick and dirty debugging link_messages
//
default
{
    link_message(integer sender_num, integer num, string msg, key id) {
        llSay(DEBUG_CHANNEL, llList2CSV([sender_num, num, msg, id]));
    }
}
// To propagate an unlimted number of arguments of any type.
// Presumed, the separator string isn't used in any source string!
//
default{  
    state_entry() {    
        list my_list = [1, 2.0, "a string", <1, 2, 3>, <1, 2, 3, 4>, llGetOwner()];  
        string list_parameter = llDumpList2String(my_list, "|");	// Typecast list to a string
        llMessageLinked(LINK_THIS, 0, list_parameter, NULL_KEY)
    }

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

Notes

Link Numbers

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 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 (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 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 unseating all avatars first.

Counting Prims & Avatars

There are two functions of interest when trying to find the number of prims and avatars on an object.

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.
}
See llGetNumberOfPrims for more about counting prims and avatars.

Errata

If a script located in a child prim erroneously attempts to access link 0, it will get or set the property of the linkset's root prim. This bug (BUG-5049) is preserved for broken legacy scripts. 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.

See Also

Events

Functions

•  llGetLinkNumber Returns the link number of the prim the script is in.

Deep Notes

Footnotes

  1. ^ LINK_ROOT does not work on single prim objects. Unless there is an avatar sitting on the object.

Signature

function void llMessageLinked( integer linknum, integer num, string str, key id );