Talk:BuildSlurl (NewAge)

From Second Life Wiki
Jump to navigation Jump to search

llEscapeURL

The use of llEscapeURL would/could simplify this function a great deal.

As for breaking the vector pos up into integers...why not make it nice and simple? If the data arrives at the function as a vector without error, we know exactly what we're dealing with and thus exactly how. llRound may not be the ideal way of integerizing the floats but it is clean.

<lsl>string SLURL(string region, vector pos) {

   return (llEscapeURL(region) + "/" + ((string)llRound(pos.x)) + "/" + ((string)llRound(pos.y)) + "/" + ((string)llRound(pos.z)));

}</lsl>

I couldn't help but fiddle about a bit. Of course the end use dictates so much how to best write any script so the script below is just the result of my fiddling before it dawned on me how many other ways the resulting object could function...I'm not writing all of 'em!

<lsl>string message_1 = "Click this link for destination information and teleport option:\n";

string message_2 = "Click this link for instant teleport:\n";

string message_3 = "This link can be used on a web site to direct users in-world:\n";

string method_1 = "secondlife://"; // Usable in-world only

string method_2 = "secondlife:///app/teleport/"; // Instant teleport

string method_3 = "http://slurl.com/secondlife/"; // Genuine slurl usable in and out-world

string region_name;

vector coords;

string SLURL(string region, vector pos) {

   return (llEscapeURL(region) + "/" + ((string)llRound(pos.x)) + "/" + ((string)llRound(pos.y)) + "/" + ((string)llRound(pos.z)));

}

default {

   on_rez(integer param)
   {
       llResetScript();
   }
   changed(integer change)
   {
       if(change & CHANGED_REGION)
       {
           llResetScript();
       }
   }
   state_entry()
   {
       // The user simply adds the destination region name and landing pos as the description of the prim (comma separated).
       list destination = llCSV2List(llGetObjectDesc());
       if(llGetListLength(destination) == 2)
       {
           // Various checks could be employed to varify the user has added the destination to the prim desc correctly (idiot proofing!)
           region_name = llList2String(destination, 0);
           coords = ((vector)llList2String(destination, 1));
           return;
       }
       else
       {
           // Otherwise the destination defaults to the prim position (Useful? Better than nothing).
           region_name = llGetRegionName();
           coords = llGetPos();
       }
   }
   touch_start(integer nd)
   {
       while(nd)
       {
           string dest = SLURL(region_name, coords);
           llInstantMessage(llDetectedKey(--nd), ("\n" + message_1 + method_1 + dest +
                                                  "\n" + message_2 + method_2 + dest +
                                                  "\n" + message_3 + method_3 + dest));
       }
   }

}</lsl>-- Fred Gandt (talk|contribs) 11:29, 28 August 2010 (UTC)