Linked Messages
Second Life objects are often made of a series of linked prims. These linked prims will move as one single object. The most important of the linked prims is the root prim. The root prim is the last prim that was linked to the object. Additionally, the root prim is the prim that translates its movement and rotation to the rest of the object. The root prim can be thought of as the “handle” by which the rest of the object is moved and rotated. The main script for an object is almost always located in the root prim.
Sometimes the linked prims in an object will need to communicate with each other. While these objects could certainly use llSay and listen events, this would not be the most efficient way to program this. Using llSay would broadcast the message well beyond the object that needs the communication. This would be very inefficient and would consume entirely too much processing time from the regional server. The best way to communicate among linked prims is to use linked messages.
A simple linked object is shown in Figure 6.4.
Figure 6.4: A Simple Linked Object

The above object contains two buttons, a red one and a green one. The cube at the top of the object changes colors depending on which button is clicked. When the buttons are touched, they send a message to the cube at the top. The green button's script is very short, and contains only a touch event. The green button's script can be seen in Listing 6.5.
Listing 6.5: The Green Button
default
{
touch_start(integer total_number)
{
llMessageLinked(LINK_ROOT , 0, "Green", NULL_KEY);
}
}
The red button is very similar to the green button. The red button can be seen in Listing 6.6.
Listing 6.6: The Red Button
default
{
touch_start(integer total_number)
{
llMessageLinked(LINK_ROOT , 0, "Red", NULL_KEY);
}
}
You will notice that the first parameter specifies which prims to send the message to. The value of LINK_ROOT sends the message to the root prim. There are several other options, as seen in Table 6.1.
Table 6.1: Message Target Types
| Type | Purpose |
|---|---|
| LINK_ROOT | Send a message to the root prim. |
| LINK_SET | Send a message to all prims. |
| LINK_ALL_OTHERS | Send a message to all prims, except the one that contains this script. |
| LINK_ALL_CHILDREN | Send a message to all non-root prims. |
| LINK_THIS | Send a message to the prim that contains the script. |
The remaining three parameters to the llMessageLinked function are sent on to the prims that receive the message. They can be used however you like. They allow an integer, a string and a key to all be sent to the receiving prim.
The root prim for this object is the box at the top that changes colors as the buttons are pressed. The script for the root prim is shown in Listing 6.7.
Listing 6.7: The Root Prim that Receives the Messages
default
{
link_message(integer sender_num, integer num, string str, key id)
{
llSay(0,"Message from " + (string) sender_num );
if( str=="Red" )
{
llSetColor(<1,0,0>,ALL_SIDES);
}
else if( str=="Green" )
{
llSetColor(<0,1,0>,ALL_SIDES);
}
}
}
As you can see a link_message event handler is implemented. It receives messages from the two buttons. Depending on which button is pressed, the color of the cube is changed.




