Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to make buttons without a script in each button.

Obsidian Stormwind
Second Life Resident
Join date: 13 Nov 2004
Posts: 16
11-02-2005 05:44
Hello,

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
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
discussion thread
11-02-2005 06:54
/54/80/69410/1.html
_____________________
i've got nothing. ;)
Dartavia Vesperia
Gorean
Join date: 19 Jul 2005
Posts: 150
11-09-2005 06:27
From: Obsidian Stormwind

I'm always looking for more efficient ways to write LSL scripts.


Hi :) I'm looking for a coder who is keen on saving lag and 'wasted scripting' practices such as you seem to be interested in as well. I have a few projects that I'm trying to get off the ground.

My point ...

I need to have a few scripts made. I would buy these scripts and need to have full copy ability to them for products I would be selling.

If you (or any other scripter reading this with a no-lag sensibility) are interested, then please contact me in world.
heehaw Odets
Registered User
Join date: 13 Jul 2005
Posts: 11
Update please
12-25-2005 09:38
I recently tried this script and for seom reason, It doesnt work.

llDetectedLinkName is not a lsl function. Is there a way to make this script work?