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

From Second Life Wiki
Jump to navigation Jump to search
(Creation of Subpage)
 
m (readability++; TODO: readability)
Line 8: Line 8:
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
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>
<lsl>
default {
default
state_entry() {
{
  llSetMemoryLimit(llGetUsedMemory()+2024);
    state_entry()
}
    {
}</lsl>
        llSetMemoryLimit(llGetUsedMemory()+2024);
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.
    }
}
</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 ==
== 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(0,"/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))
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>
<lsl>
AvTalk(string msg, key id) {
AvTalk(string msg, key id)
  string org_name = llGetObjectName();
{
  llSetObjectName(llGetDisplayName(id));
    string obj_name = llGetObjectName();
  llSay(0,msg);
 
  llSetObjectName(org_name);
    llSetObjectName(llGetDisplayName(id));
    llSay(PUBLIC_CHANNEL, msg);
 
    llSetObjectName(obj_name);
}
}
</lsl>
</lsl>
Line 29: Line 35:


<lsl>
<lsl>
AvTalk(string msg, key id) {
string text_string;
string org_name = llGetObjectName();
 
llSetObjectName(llGetDisplayName(id));
AvTalk(string message, key id)
llSay(0,msg);
{
llSetObjectName(org_name);
    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);
        }
    }
}
}
string text_string;
</lsl>
default {
state_entry() {
  llListen(1,"",llGetOwner(),"");
  llOwnerSay("Ready To Test (type /1<message> to set message the person who touches will say");
}
listen(integer chan, string name, key id, string msg) {
  text_string = msg;
  llOwnerSay("Next Person to touch this object will say "+text_string);
}
touch_start(integer touch_number) {
  if(llStringLength(text_string)>=1) AvTalk(text_string,llDetectedKey(0));
  else AvTalk("Nothing has been set",llDetectedKey(0));
}
}</lsl>

Revision as of 16:01, 3 August 2013

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>