Difference between revisions of "LinksetIndexing"

From Second Life Wiki
Jump to navigation Jump to search
m (Replaced <source> with <syntaxhighlight>)
 
Line 10: Line 10:
Searches for multiple prims that share a common specific name and returns a list of linkset numbers. Otherwise an empty list if none found.
Searches for multiple prims that share a common specific name and returns a list of linkset numbers. Otherwise an empty list if none found.


<source lang="lsl2">
<syntaxhighlight lang="lsl2">
list LinkedList(string Needle) {
list LinkedList(string Needle) {
     list Needles;
     list Needles;
Line 18: Line 18:
     return Needles;
     return Needles;
}
}
</source>
</syntaxhighlight>


{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
Line 46: Line 46:
Searches for a single prim that has a specific name. Returns 0 if not found.
Searches for a single prim that has a specific name. Returns 0 if not found.


<source lang="lsl2">
<syntaxhighlight lang="lsl2">
integer Linked(string Needle) {
integer Linked(string Needle) {
     integer Prims = llGetNumberOfPrims()+1;
     integer Prims = llGetNumberOfPrims()+1;
Line 52: Line 52:
     return FALSE;
     return FALSE;
}
}
</source>
</syntaxhighlight>


{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
Line 81: Line 81:
Searches and replaces all strings in Needles list with integer linkset numbers, where the strings exactly match a prim name.
Searches and replaces all strings in Needles list with integer linkset numbers, where the strings exactly match a prim name.


<source lang="lsl2">
<syntaxhighlight lang="lsl2">
list ListLinked(list Needles) {
list ListLinked(list Needles) {
     integer Prims = llGetNumberOfPrims()+1;
     integer Prims = llGetNumberOfPrims()+1;
Line 90: Line 90:
     return Needles;
     return Needles;
}
}
</source>
</syntaxhighlight>


{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
Line 120: Line 120:
Create a global integer for each linkset you want to track and then an if-else condition to assign the linkset number to it.
Create a global integer for each linkset you want to track and then an if-else condition to assign the linkset number to it.


<source lang="lsl2">
<syntaxhighlight lang="lsl2">
integer Foot;
integer Foot;
integer Leg;
integer Leg;
Line 137: Line 137:
     while(--Prims > 1);
     while(--Prims > 1);
}
}
</source>
</syntaxhighlight>


<div style="float:right;font-size: 80%;">
<div style="float:right;font-size: 80%;">
Released into public domain. By Nexii Malthus.</div>
Released into public domain. By Nexii Malthus.</div>
|}
|}

Latest revision as of 17:20, 9 February 2023

By Exact Name

One Name - Multiple Links

Searches for multiple prims that share a common specific name and returns a list of linkset numbers. Otherwise an empty list if none found.

list LinkedList(string Needle) {
    list Needles;
    integer Hay = 1;
    integer Stacks = llGetNumberOfPrims();
    for(; Hay <= Stacks; ++Hay ) if(llGetLinkName(Hay) == Needle) Needles += Hay;
    return Needles;
}
Input Description
string Needle Common name that multiple prims share.
Output Description
return list LinkedList Returns list of linkset numbers that have exactly same prim name as Needle does.
Released into public domain. By Nexii Malthus.


One Name - One Link

Searches for a single prim that has a specific name. Returns 0 if not found.

integer Linked(string Needle) {
    integer Prims = llGetNumberOfPrims()+1;
    while(--Prims) if(llGetLinkName(Prims) == Needle) return Prims;
    return FALSE;
}
Input Description
string Needle Specific name that a prim possesses.
Output Description
return integer Linked Returns integer linkset number of a prim that has exactly same prim name as Needle does.
Released into public domain. By Nexii Malthus.


Multiple Names - One Link each

Searches and replaces all strings in Needles list with integer linkset numbers, where the strings exactly match a prim name.

list ListLinked(list Needles) {
    integer Prims = llGetNumberOfPrims()+1;
    while(--Prims) {
        integer Ptr = llListFindList(Needles,[llGetLinkName(Prims)]);
        if(~Ptr) Needles = llListReplaceList(Needles,[Prims],Ptr,Ptr);
    }
    return Needles;
}
Input Description
list Needles Specific names that prims possess.
Output Description
return list ListLinked Returns list of linksets number of prims that had exact same prim names as the list position in Needles did.
Released into public domain. By Nexii Malthus.


Multiple Names - Roll Your Own Loop

This is how I do most of my linkset indexing. A loop with if-else conditions, it is as simple as you can get.

Create a global integer for each linkset you want to track and then an if-else condition to assign the linkset number to it.

integer Foot;
integer Leg;
integer Torso;
integer Head;

LinksetInit() {
    integer Prims = llGetNumberOfPrims();
    do {
        string Prim = llGetLinkName(Prims);
        if(Prim == "Foot") Foot = Prims; else
        if(Prim == "Leg") Leg = Prims; else
        if(Prim == "Torso") Torso = Prims; else
        if(Prim == "Head") Head = Prims;
    }
    while(--Prims > 1);
}
Released into public domain. By Nexii Malthus.