From: Argent Stonecutter
link_by_name will return the first object that matches the name.
To get all of them you have to do a loop and return a list:
list links_by_name(string name)
{
integer i = llListFindList(names,[name]) + 1;
list l;
list tmp = names;
integer n;
while(i > 0) {
n += i;
l += n;
tmp = llList2List(tmp, i, -1);
i = llListFindList(tmp,[name]) + 1;
}
return l;
}
list names;
list reds;
list blues;
init_names()
{
integer n = llGetNumberOfPrims();
integer i;
for(i = 1; i <= n; i++) names += llGetLinkName(i);
reds = links_by_name("red");
blues = link_by_name("blue");
}
integer link_by_name(string name)
{
return llListFindList(names, [name]) + 1;
}
default
{
state_entry()
{
init_names();
}
changed(integer change)
{
if(change & CHANGED_LINK)
{
init_names();
}
}
touch_start(integer total_number)
{
integer n;
integer i;
// turn all the reds blue:
n = llGetListLength(reds);
for(i = 0; i < n; i++) {
llSetLinkColor(llList2Integer(reds, i),<0,0,1>,ALL_SIDES);
}
}
}
Optimizing the init function to avoid having the extra list and the search function is left to the reader.

edited with removal of text only for space.ty.
Hi, i tried to PM ya Argent but i think i deleted the PM.

I'm still learning this forums way of thinking.. lol.. I had a question bout your post above..
I made a test and in the test script..
(1) removed the " link by name" as that was not needed for test.
(2) kept all else you wrote also excluding the lists for red an blue since i made a temp list to hold name of prim i called from my link-set.. all works great but.
it won't find the last prim in the linkset.. i eliminated everything that would have interupted the process but the best i could do is exchange a # to get it to actually find an interpret the last prim ..i was like really happy till i was baffled as to why NOW it : Script run-time error & : Stack-Heap Collision on the Second prim of link set ,wile accepting all the others..
Soo, in conclusion to my Q'n.. why would it ether
(A) memory crash on the last prim an not the rest or
(B) memory crash on the second prim an not the rest.. ether or
i can't seem to get it to work right.. IMHO..the script does exactly what i was hoping for but i would hate to have to add a function to ignore or hide the last prim in linkset just to avoid a memory error if thats what run-time error is..
I was able to conclude that this error ONLY originated when the {{list links_by_name(string name)}} function was called.. as on this test an all others.. everything upto that said function worked perfect.. the {{ init_names() }} worked perfect aswell.. i have no clue though as to why the one function does what it does or how i could fix it without breaking its intended purpose..
any help on this would be GREATLY appreciated as i am soo close to getting this test to work flawlessly with your help but with a lotsa bumps an bruising from racking head on desk. ;-D thx. heres the test i was using. .
[/php]
list names;
list TMPO;
integer x = TRUE;
string name = "Spike";
list links_by_name(string name)
{
integer i = llListFindList(names,[name]) + 1;
list l;
list tmp = names;
integer n;
while(i > 0) {
n += i;
l += n;
tmp = llList2List(tmp, i, -1);
i = llListFindList(tmp,[name]) + 1;
}
return l;
}
init_names()
{
integer n = llGetNumberOfPrims();
integer i;
for(i = 1; i <= n; i++) names += llGetLinkName(i);
TMPO = links_by_name("name"

;
}
default
{
state_entry()
{
init_names();
}
touch_start( integer n )
{
x=!x;
if(x)
{
llOwnerSay(" Button selected: " + name
+ "\n # Of prims: " + ((string)llGetNumberOfPrims())
+ "\n # Revised Main list: " + ((string) links_by_name( "path"

));
}
else
{
llOwnerSay(" Button selected: " + name
+ "\n # Of prims: " + ((string)llGetNumberOfPrims())
+ "\n # In Main list: " + ((string) names));
}
}}[/php]
{ note } that I used 6 prims linked with the last linked prim named "path" an the prim named "Spike" could be Any other prim in the same link set, thx.