I've noticed that many machines in Second Life use a separate script for each prim that acts as a button in an object, usually using a MessageLinked() function to send a message to the script in the root prim. However, seeing how this adds to the total script count in a SIM, I thought I'd post a way to reduce the need for these types of scripts.
Take a look at the code snippet below:
CODE
default
{
touch_start(integer total_number)
{
if(llGetLinkName (llDetectedLinkNumber(0)) == "Button1")
{
// Whatever Button1 does...
}
else if(llGetLinkName (llDetectedLinkNumber(0)) == "Button2")
{
// Whatever Button2 does...
}
// And so on...
}
}
This would be code stored in the root prim. As long as the individual prims for the buttons are uniquely named ("Button1" and "Button2" in this example), then one can contain all the scripting needed in the primary script and not need to have a child script for each button.
Seeing how most simple vendors scripts use 3 scripts, one for the primary script in the root prim and one for each button ("Next" and "Previous"
, this technique would reduce the number of scripts by 1/3rd. And for vendors with a whole lot of buttons? I've seen one vendor with at least 36 scrtipts. If one takes out the scripts for buttons one would reduce the number of scripts by at least 26.Let me know if you can see any improvements, or better way to do this code.
I'm always looking for more efficient ways to write LSL scripts.Obsidian Stormwind