I like so many am still learning LSL. Kind of think we will always be learning something new, no matter how advanced. To me the wiki really wasn't all that clear on passing touchs and Joannah's little script snippet said it all so simply.
I have just been playing with it and added another trick into it also. For the ones that follow us and do a search for DetectedLinkNumber and come across this thread:
A person could put this script into different prims and get it to change it's color and say the color:
default {
touch_start( integer n ) {
llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1, 0, 0>, 0.6]);
llOwnerSay("My color is red");
}
}
But you would have to put the script in each prim and could not use that in a linkset. It would only affect the root prim, no matter which prim you touched. So you can do this instead. Link four prim and put this in the root prim:
default {
touch_start( integer n ) {
integer child = llDetectedLinkNumber( 0);
string childname = llGetLinkName( child );
if(child == 2){
llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1, 0, 0>, 0.6]);
llOwnerSay( "Child Prim name: " + childname +
", link #" + (string)child + " touched." );
}
if(child == 3){
color = <0, 0, 1>;
llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <0, 0, 1>, 0.6]);
llOwnerSay( "Child Prim name: " + childname +
", link #" + (string)child + " touched." );
}
if(child == 4){
color = <0, 1, 0>;
llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <0, 1, 0>, 0.6]);
llOwnerSay( "Child Prim name: " + childname +
", link #" + (string)child + " touched." );
}
}
}
Now you have saved the sim several scripts and could also use that in a hud. But you can also save some script memory by creating your own functions. If you look closely, you can see that you can even place one user defined function inside another user defined function. Same setup; create a linkset of 4 prim and place in root:
integer child;
string childname;
vector color;
say(){
llOwnerSay( "Child Prim name: " + childname +
", link #" + (string)child + " touched." );
}
params(){
llSetPrimitiveParams([PRIM_COLOR, 4, color, 0.6]);
say();
}
default {
touch_start( integer n ) {
child = llDetectedLinkNumber( 0);
childname = llGetLinkName( child );
if(child == 2){
color = <1, 0, 0>;
params();
}
if(child == 3){
color = <0, 0, 1>;
params();
}
if(child == 4){
color = <0, 1, 0>;
params();
}
}
}