Bot-Babes/Boys

 

Using Link Messages

Page history last edited by mariahartog@... 2 yrs ago

 

As we have several scripts, we need to use link messages to pass data from one to another. The function llMessageLinked is used to send a link message from one script to another. When a prim receives a link mesage, every script in that prim will have its link_message event triggered.

Linknum
For the purposes of this example, Linknum will be set to LINK_SET. This means that every link message will be sent to every prim. This example is so small that any performance issues over doing it this way are insignificant.

num
All our data is going to be packed into the string variable, so num can be redundant. But in this example I'm going to use it as a method of identifiying link messages from YOUR scripts.. This has a couple of advantages.

Ability to mix your scripts with other peoples scripts

No error checking when used with other peoples scripts.

Possible public interface.

To do this, pick a number, call it your Company Channel. Use this value for num in all your link messages. In the link events, always check to see if the company channel is correct. If it is, you know that it is a message from one of your scripts, and the data will be in a expected format. Now, if you swap scripts with someone else doing the same thing with num, your scripts will not clash with each other as they wil have different nums. If you publish your link message formats and company channel, then others can buy your scripts, and use them via the link messages. This allows scripts to act like computer chips from different manufacturers all wired together.

Data marshalling
The message containing the information on where to move is going to contain a mixture of data types. More than can be fit into one link message, and containing data types that the link message cannot handle. So we need a method of marshalling the data into a link message.

And there just happens to be a perfect example of how to do this on this wiki, ExampleArgumentMultiplexing

So for a "move to " message, we will probably want to send the following information.

A string contain the message type

A vector containing the target location

A float containing a speed

A float containing a range

Dropping all that in the multiplexing example's code:

integer company_channel = 250;//The channel number your scripts will use
    float speed = 2; //How fast the object is to move
    vector new_target  = <100,23,45>;//Where the object should move to
    float range = 0.5;//How near to the target the object should get.
    list command=["MOVETO",new_target,speed,range];
    llMessageLinked( LINK_SET, company_channel, llDumpList2String(command, "-=-"), "" );

Data unmarshalling

In a similar way, this is how we get our data out. Note where the company channel is being checked.

link_message(integer sender_num, integer num, string str, key id)
{
     list Arguments = llParseStringKeepNulls( str, ["-=-"], [] );
     string Command = llList2String( Arguments, 0 );
    if(num == company_channel)
    {
         if( Command == "MOVETO" )
         {
              vector new_target = (vector)llList2String( Arguments, 1 );
              float speed = (float)llList2String( Arguments, 2 );
              float range = (float)llList2String( Arguments, 3 );
              ...
         }
         else ...
    }
}

This is the method that will be used throughout this example.

Back to the Create a flying pet home page

Back to the Script Library

Comments (0)

You don't have permission to comment on this page.