Difference between revisions of "User:Myst Leissa/Snippets"

From Second Life Wiki
Jump to navigation Jump to search
m (readability++; TODO: readability)
m (Links Added)
Line 78: Line 78:
}
}
</lsl>
</lsl>
[[User:Myst_Leissa|Back to the my main profile]]

Revision as of 22:32, 3 July 2014

Template:Wifify Note: If you decide and/or find a better way to list these snippets, I give you my trust and my permission as author to put them where you think they will be most useful, without jeopardizing the rules governing SL Wiki Entry creation. --Myst Leissa 20:41, 31 July 2013 (PDT)

Myst's Snippet Library

If I'm understanding how userpages work this should be a subpage of my userpage, if that is correct then these will be helpful snippets for Scripters both old and new.

Memory Control

While my content often includes memory limiters I felt I should make a minor snippet to explain how best to implement a MONO Script Memory Limiter <lsl> default {

   state_entry()
   {
       llSetMemoryLimit(llGetUsedMemory()+2024);
   }

} </lsl> Explaination: The reason I call llGetUsedMemory()+2024 is for llGetUsedMemory() it returns the amount of memory a script uses at that exact time, however to limit it exactly to that js a mistake that will lead to buffer overflow and stackheap collisions. The answer is to offset the amount of memory by a few kilobytes extra for the script to process new information with. Depending on the content of your script it may actually be more effective to leave certain scripts unlimited while limiting the rest, this is most often the case in scripts where you expect large lists to form after initialization.

SayAsAvatar Snippet

This Function will execute the LSL Command to create a line of text in a Given Avatar's Display Name by Key. (ie instead of llSay(PUBLIC_CHANNEL, "/me "+llGetDisplayName(llDetectedKey(0)+" hides") Which will produce the emote of the "<object name>: <display_name> Hides" You Can Instead use this snippet to cut off <object name> and replace it with the llGetDisplayName(llDetectedKey(0))

<lsl> AvTalk(string msg, key id) {

   string obj_name = llGetObjectName();
   llSetObjectName(llGetDisplayName(id));
   llSay(PUBLIC_CHANNEL, msg);
   llSetObjectName(obj_name);

} </lsl>

An Example of how to use this is:

<lsl> string text_string;

AvTalk(string message, key id) {

   string obj_name = llGetObjectName();
   llSetObjectName(llGetDisplayName(id));
   llSay(PUBLIC_CHANNEL, message);
   llSetObjectName(obj_name);

}

default {

   state_entry()
   {
       key owner = llGetOwner();
       llListen(1, "", owner, "");
       llOwnerSay("Ready to test, type /1<message> to set message the person who touches will say.");
   }
   listen(integer channel, string name, key id, string message)
   {
       text_string = message;
       llOwnerSay("Next Person to touch this object will say '" + text_string + "'.");
   }
   touch_start(integer num_detected)
   {
       key id = llDetectedKey(0);
       if (llStringLength(text_string))
       {
           AvTalk(text_string, id);
       }
       else
       {
           AvTalk("Nothing has been set.", id);
       }
   }

} </lsl>

Back to the my main profile