Simplex Text

From Second Life Wiki
Revision as of 12:38, 15 March 2011 by Rudy Glassfield (talk | contribs)
Jump to navigation Jump to search

Simplex Text is, in the creator's opinion, the successor to XyzzyText. Whether that is true or not, the future will decide. Simplex provides end users an easy way to generate dynamic text on prims. Using only one texture and one script, this becomes a viable option for many users. Unfortunately, unlike XyzzyText, it uses a linkset, rather than a single prim, to visualize its contents.

Rudy Glassfield, the sole developer of Simplex Text, has made the script open-source and currently sells it on the Marketplace for free. The script comes packaged in a box, which doubles up as a demo for the Simplex Text System.

The script is also available here on the Wiki, for those intrepid users who wish to dive right in.

Template:LSL SCRIPT

// PRELIMINARY NOTES: // // ALL CHARACTER PRIM BLOCKS MUST BE NAMED "CHARACTER" THIS IS DONE TO ENSURE NO OTHER PRIMS ARE ALTERED. // ALL OBJECTS MUST BE LINKED. THIS SCRIPT IS IN THE ROOT PRIM.

// PLEASE MODIFY THESE VARIABLES TO YOUR LIKING

integer face = 3; // FACE NUMBER WHICH THE LETTERS WILL SHOW UP ON (USE ALL_SIDES IF YOU'RE NOT SURE) vector color = <1, 1, 1>; // COLOR OF TEXT <1, 1, 1> = (RGB) WHITE, <0, 0, 0> = (RGB) BLACK

// END USER CONTENT

list charOrder = []; key ascii = "b2e7394f-5e54-aa12-6e1c-ef327b6bed9e"; string gCharIndex = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz"; float xOrigin = -0.450; float yOrigin = -0.550; setCharacter(integer linknum, string msg) {

   integer index = llSubStringIndex(gCharIndex, msg);
   float xOffset = xOrigin + (index % 10)/10.f;
   if(xOffset > 1) xOffset -= 1.f;
   if(xOffset < -1) xOffset += 1.f;
   float yOffset = yOrigin - (index / 10)/10.f;
   if(yOffset > 1) yOffset -= 1.f;
   if(yOffset < -1) yOffset += 1.f;
   llSetLinkPrimitiveParamsFast(linknum, [PRIM_TEXTURE, face, ascii, <0.1, 0.1, 0>, <xOffset, yOffset, 0>, 0, PRIM_COLOR, face, color, 1.0]);

}

setCharacters(string msg, list order) {

   integer i;
   for(i = 0; i < llGetListLength(order); i ++)
   {
       setCharacter(llList2Integer(order, i), llGetSubString(msg, i, i));
   }

} default {

   state_entry()
   {
       list temp;
       
       // Set Up Letter Blocks
       
       integer linked = llGetNumberOfPrims();
       
       integer i;
       for(i = 2; i <= linked; i ++)
       {
           if(llGetLinkName(i) == "Character")
           {
               vector pos = llList2Vector(llGetLinkPrimitiveParams(i, [PRIM_POSITION]), 0);
               vector posNorm = llVecNorm(pos)*llGetRot();
               temp += pos*llRot2Up(llGetRot())+posNorm.x;
               temp += i;
           }
       }
       charOrder = llList2ListStrided(llDeleteSubList(llListSort(temp, 2, FALSE), 0, 0), 0, -1, 2);
   }
   link_message(integer linknum, integer num, string str, key id)
   {
       llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN, [PRIM_COLOR, ALL_SIDES, <0, 0, 0>, 0.0]);
       setCharacters(str, charOrder);
   }
   changed(integer change)
   {
       if(change & CHANGED_LINK)
       {
           llResetScript();
       }
   }

}