Difference between revisions of "Link message"

From Second Life Wiki
Jump to navigation Jump to search
m (The two code examples had conflicting styles. I adjusted the oddball to the style used on most of the other LSL pages.)
m (some minor readability improvements in the code)
Line 17: Line 17:
default
default
{
{
     touch_start(integer c)
     touch_start(integer num_detected)
     {
     {
         llMessageLinked(LINK_THIS, 0, llDetectedName(0), llDetectedKey(0));
         llMessageLinked(LINK_THIS, 0, llDetectedName(0), llDetectedKey(0));
     }
     }
     link_message(integer source, integer num, string str, key id)
     link_message(integer source, integer num, string str, key id)
     {
     {
         llWhisper(0, str + " (" + (string)id + ") touched me!");
        // PUBLIC_CHANNEL has the integer value 0
         llWhisper(PUBLIC_CHANNEL, str + " (" + (string)id + ") touched me!");
     }
     }
}
}
Line 32: Line 34:


default
default
{       // To propagate an unlimited number of arguments of any type.
{
// Presumed, the separator string isn't used in any source string!
    // To propagate an unlimited number of arguments of any type.
    // Presumed, the separator string isn't used in any source string!
 
     state_entry()  
     state_entry()  
     {     
     {     

Revision as of 15:57, 6 October 2012

Description

Event: link_message( integer sender_num, integer num, string str, key id ){ ; }

Triggered when the script receives a link message that was sent by a call to llMessageLinked. llMessageLinked is used to send messages from one script to another.

• integer sender_num The link number of the prim that contained the script that called llMessageLinked.
• integer num Second parameter of the llMessageLinked call.
• string str Third parameter of the llMessageLinked call.
• key id Fourth parameter of the llMessageLinked call.

id is often used 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. The sizes of str and id are only limited by available script memory.

Caveats

  • 64 link_message events can queue, past that, they are silently dropped! Don't do too much in the event if they might be coming in fast.
  • sender_num does not reflect how a message was sent, there is no way to know if it was sent with a LINK_* flag or the specific link number.
  • If str and id are bigger than available memory the script will crash with a Stack-Heap Collision.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> //This is just an example script, you shouldn't handle touches within single script this way.

default {

   touch_start(integer num_detected)
   {
       llMessageLinked(LINK_THIS, 0, llDetectedName(0), llDetectedKey(0));
   }
   link_message(integer source, integer num, string str, key id)
   {
       // PUBLIC_CHANNEL has the integer value 0
       llWhisper(PUBLIC_CHANNEL, str + " (" + (string)id + ") touched me!");
   }

} </lsl>

Useful Snippets

<lsl> // This is just an example script, you shouldn't handle link message within single script this way.

default {

    // To propagate an unlimited 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, "

Notes

A script can hear its own link messages.

See Also

Functions

•  llMessageLinked

Deep Notes

Signature

event void link_message( integer sender_num, integer num, string str, key id );