LlMessageLinked
From Second Life Wiki
(Redirected from LSL llMessageLinked)
| LSL Portal | | | Functions | | | Events | | | Types | | | Operators | | | Constants | | | Flow Control | | | Script Library | | | Tutorials |
Contents |
Description
Function: llMessageLinked( integer linknum, integer num, string str, key id );| 164 | Function ID |
| 0.0 | Delay |
| 10.0 | Energy |
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 linknum.
| • integer | linknum | – | Link number or a LINK_* flag, controls which prim(s) receive the link_message. | |
| • integer | num | – | Value of the second parameter of the resulting link_message event. | |
| • string | str | – | Value of the third parameter of the resulting link_message event. | |
| • key | id | – | Value of the forth parameter of the resulting link_message event. |
You can use id as a second string field[1]. The sizes of str and id are only limited by available script memory.
|
| |||||||||||||||||||||
Caveats
- A script can hear its own linked messages if linknum targets the prim it is in[2]. 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. In addition to this if multiple messages are sent one after another, the lag can cause the event queue to fill and drop messages.
- Avoid sending link_messages to a target faster then 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_num 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 } }
Useful Snippets
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.
- 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 (ie. not all prims receive the message). 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, and use a single link message to address them. -- Void Singer
Footnotes
- ^ In 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.
- ^ There 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).
See Also
Events
| • | link_message |
Functions
| • | llGetLinkNumber | – | Returns the link number of the prim the script is in. |
This article wasn't helpful for you? Maybe the related article at the LSL Wiki is able to bring enlightenment.

