LZW LSL Examples

From Second Life Wiki
Revision as of 14:35, 18 September 2008 by Haravikk Mistral (talk | contribs) (New page: {{LSL Header}} = LZW LSL Examples = == Description == The following LSL code snippets show examples of using the LZW engine by [[User:Haravikk Mistral|Haravikk ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

LZW LSL Examples

Description

The following LSL code snippets show examples of using the LZW engine by Haravikk Mistral. These examples require that you add any relevant functions and constants from the helpers code where noted.

States are used in these scripts for clarity, but are not necessary to the operation of the scripts themselves.

Examples

Compress a message

<lsl>string myMsg = "Hello world! I am a lovely message waiting to be compressed!";

// Add necessary functions from https://wiki.secondlife.com/wiki/LZW_LSL_Helpers here

default {

   state_entry() { // Send our message
       llResetTime();
       lslLZWCompressBase64ToBase64(
           LINK_THIS,
           llStringToBase64((myMsg = "") + myMsg),
           llGetOwner()
       );
   }

   link_message(integer x, integer y, string msg, key id) {
       if (!lslLZWIsReply(y, id)) return;
       
       y = lslLZWGetReplyMode(y);
       if (y == LSLLZW_COMMAND_ERROR) 
           llOwnerSay("COMPRESS ERROR: "+msg);
       else if (y == LSLLZW_COMMAND_COMPRESS) 
           llOwnerSay("Compressed: "+msg);
   }

}</lsl>

Decompress a message

<lsl>string myMsg = "Hello world! I am a lovely message waiting to be compressed!";

// Add necessary functions from https://wiki.secondlife.com/wiki/LZW_LSL_Helpers here

default {

   state_entry() { // Send our message
       llResetTime();
       lslLZWDecompressBase64ToBase64(
           LINK_THIS,
           (myMsg = "") + myMsg,
           llGetOwner()
       );
   }

   link_message(integer x, integer y, string msg, key id) {
       if (!lslLZWIsReply(y, id)) return;
       
       y = lslLZWGetReplyMode(y);
       if (y == LSLLZW_COMMAND_ERROR) 
           llOwnerSay("COMPRESS ERROR: "+msg);
       else if (y == LSLLZW_COMMAND_DECOMPRESS) 
           llOwnerSay("Decompressed: "+llBase64ToString((msg = "") + msg));
   }

}</lsl>