LSL Protocol/EasyTalk

From Second Life Wiki
< LSL Protocol
Revision as of 12:40, 25 January 2015 by ObviousAltIsObvious Resident (talk | contribs) (<lsl> tag to <source>)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Back to Protocol page

Easy Talk Protocol

The problem: coordinate object either using llSay or llMessageLinked in a linkset, using a single channel where objects can understand:

  • sender (who generated the message and shoule be possibly replied)
  • destination (to select object who should handle the message)
  • command (which action to perform)
  • free form parameters

Protocol is implemented using a very simple List/String dumping parsification using the character "|" as separator. Since this is a very easy protocol I just choose this character which is common on keyboards, but very unlikely to be used in general. It is also very simple to input in notecards and so you can have a very generic message handling and serialization. Should you feel that "|" is not to be used because conflicting with your schema you can change it with %255, but in this way you lose the notecard serialization. Also the protocol doesn't handle the float to string problem, which under "normal" situations should not be a big problem.

If you need to have

  • "|" character in your strings
  • maximum precisions in float (more than 3-4 decimals)

Don't use this or adapt with proper serialization.

On the other hand the advantage are:

  • very simple
  • low footprint (you can even inline it)
  • very fast (no complex serializations needed)


And here the basic code (you can even inline these functions but leaving it as function will allow for refactoring and ease the code understanding):

Serialization / Deserialization

string dumpList(list lst)
{
    return llDumpList2String(lst,"|");
}
list parseString(string str)
{
    return llParseStringKeepNulls(str,["|"],[]);
}


When needing to send a message use the following:

// for linkset:
llMessageLinked(LINK_SET,1,dumpList( [ sME, "TEXT", "SHOW", str, vcolor ]),""); 

// for say channels:
llSay(CHANNEL,dumpList( [ sME, "TEXT", "SHOW", str, vcolor ] );

When needing to execute the command do something like:

    link_message(integer channel,integer num, string message,key id)
    {
        debug("got msg "+message);
        // message has the form [ from, to, cmd, parms ]
        list array=parseString(message);
        string src=llList2String(array,0);
        string dst=llList2String(array,1);
        string cmd=llToLower(llList2String(array,2));
        string parm1=llList2String(array,3);
        string color=llList2String(array,4);
        
        // answers only if we are the target
        if(dst!=sME) return;

Note the use of sME for each script for rapid deciding it's me.

Each object in the linkset listening area should have unique sME global variable.

Protocol allows for broadcasting messages for special situations:

RESET!!!

for example allowed for resetting all pieces.