User:Nexii Malthus/Script API

From Second Life Wiki
< User:Nexii Malthus
Revision as of 11:46, 11 May 2009 by Nexii Malthus (talk | contribs) (New page: Based from LSL To Client Communication I decided to go ahead and attempt to fully implement a modified version of the protoc...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Based from [To Client Communication] I decided to go ahead and attempt to fully implement a modified version of the protocol.

Please see Dale's implementation first, so not everything has to be repeated here and you might see the slight differences in my protocol.

Protocol

Before anything can be queried, a connection has to be made with the client by agreeing on a common channel for receiving responses. The protocol uses tokens like Dale's implementation. Any message addressed to the viewer has to begin with 'Vwr'.

The connection is made with the command Connect, followed by a channel number. Query: $Vwr$Connect$123456

The client will then verify this connection by an 'Ok.' on the channel. Repeating the query with a different channel will change the agreed upon channel to the new one.

Once a connection is made, the LSL Script can execute all the other queries

There are some general basic functions. $Vwr$Capabilities $Vwr$Client $Vwr$Creator $Vwr$OperatingSystem

Then there are 'Packages' or 'Extensions', much like in Dale's implementation, but not really requiring a full name of the creator.

The two current extensions are 'Nexii' and 'Permission'.

Permission is used to request permission from the user for client-side powers of various functions that may need special User permission granted first. $Vwr$Permission$NexiiPicker

'Nexii' is empty at the time of writing but im implementing a function for being able to receive 'touches' in the world or clicks aka Picker. $Vwr$Nexii$Picker$<Arguments> $Vwr$Nexii$Picker$World|Once $Vwr$Nexii$Picker$HUD|All $Vwr$Nexii$Picker$Once|HUD|World

Example

This is a working example LSL Script <lsl> list Data = []; integer Tick;

default{

   state_entry(){
       llSetColor( <1,0,0>, -1 );
       llListen( 30, "", "", "" );
   }
   
   touch_start( integer dn ){
       llSetColor( <1,0,0>, -1 );
       llSay( 0,"Creating connection to owner..." );
       llOwnerSay( "$Vwr$Connect$30" );
   }
   
   listen( integer ch, string nm, key k, string msg ){
       if( msg == "Ok." ) state Two;
   }

}

state Two{

   state_entry(){
       llSay( 0, "Connection successful." );
       llSetColor( <1,1,0>, -1 );
       llListen( 30, "", "", "" );
       Tick = 0; Data = [];
       llSay( 0, "Executing functions..." );
       llOwnerSay( "$Vwr$Capabilities" );
   }
   
   listen( integer ch, string nm, key k, string msg ){
       if( Tick == 0 ){
           Data += msg; ++Tick;
           llOwnerSay( "$Vwr$Creator" );
       } else if( Tick == 1 ){
           Data += msg; ++Tick;
           llOwnerSay( "$Vwr$OperatingSystem" );
       } else if( Tick == 2 ){
           Data += msg;
           state Three;
       }
   }

}

state Three{

   state_entry(){
       llSetColor( <0,1,0>, -1 );
       llSay( 0,"Complete. Debug:\n"+
           "Capabilities: "+llList2String(Data,0) +"\n"+
           "Creator: "+llList2String(Data,1) +"\n"+
           "OS: "+llList2String(Data,2) );
   }

} </lsl>