I find it a pain in the butt to continually search though previous scripts to find out how I’ve done things, so this is simply a repository of LSL snippet that I use. It’s quick and easy for me, and I hope that some of these may serve you as well. Expect this list to grow as my scripting experiences increases. Note: The intent of this document is NOT to explain or teach, there are many far more qualified than I do perform this task; this is merely a convenience for me and those who are looking for quick and simple shortcuts to getting the job done.
Count instances of a character in a string
llGetListLength(llParseStringKeepNulls(message, ["char_to_count"], []))-1;
Using chat to do things (listeners)
// Global vars: Used for chat and menus
integer listener_handle;
integer listen_channel = 123;
// Set the listener for chat and menu commands (in default state state_entry(), usually)
listener_handle = llListen( listen_channel, "", llGetOwner(), "" );
listen(integer channel, string name, key id, string message) {
message = llToLower(message);
name = llToLower(name);
if (message == "trigger_command") {
... do stuff here...
}
}
Pulsing a glow effect
// Glow parameters
float gGlow = 0.10;
float gGlowTop = 0.50;
float gGlowBottom = 0.05;
float gGlowIncrement = 0.05;
// Pulse parameters 0 for decrement, 1 for increment
integer gPulseDirection = 0;
integer gPulseSpeed = .01;
default
{
touch_start(integer total_number)
{
llSetTimerEvent(gPulseSpeed);
}
// Pulse the glow
timer()
{
// Glow: increment up, and down (like it's pulsing)
if (gGlow >= gGlowTop) {
gPulseDirection = 0;
}
if (gGlow <= gGlowBottom) {
gPulseDirection = 1;
}
if ( gPulseDirection ) {
gGlow += gGlowIncrement;
} else {
gGlow -= gGlowIncrement;
}
llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, gGlow]);
}
}


