Difference between revisions of "LlGetLinkNumber"

From Second Life Wiki
Jump to navigation Jump to search
(no never exceeds, yes may equal, yes does equal in the test case of last prim of object with multiple prims but no sitting avatars)
m (Added a note about using double negation to get a link number that can be used with an unlinked prim or the root of a linkset.)
 
(4 intermediate revisions by 4 users not shown)
Line 3: Line 3:
|func=llGetLinkNumber
|func=llGetLinkNumber
|return_type=integer
|return_type=integer
|func_footnote=0 means the prim not linked, 1 the prim is the root, 2 the prim is the first child, etc.
|func_footnote=<code>0</code> means the prim is not linked, <code>1</code> the prim is the root, <code>2</code> the prim is the first child, etc. Links are numbered in the reverse order in which they were linked -- if you select a box, a sphere and a cylinder in that order, then link them, the cylinder is 1, the sphere is 2 and the box is 3. The last selected prim has the lowest link number.
|func_desc
|func_desc
|return_text=that is the link number of the prim containing the script.
|return_text=that is the link number of the prim containing the script.
Line 9: Line 9:
|caveats=*By design may equal [[llGetNumberOfPrims]], ''e.g.'', when prim is last, object contains multiple prims, and no sitting avatars
|caveats=*By design may equal [[llGetNumberOfPrims]], ''e.g.'', when prim is last, object contains multiple prims, and no sitting avatars
|constants
|constants
|examples=
|examples=<source lang="lsl2">default
<pre>
default
{
{
     state_entry()
     state_entry()
Line 18: Line 16:
         llOwnerSay((string) llGetNumberOfPrims());
         llOwnerSay((string) llGetNumberOfPrims());
     }
     }
}
}</source>
</pre>
A non-obvious feature is using double-negation to obtain a link number zero (for an unlinked prim) or one (for the root of a linkset). Unlike constants like [[LINK_ROOT]], this number can be used directly with functions like [[llGetLinkPrimitiveParams]] without first determining whether a prim is part of a linkset:
<source lang="lsl2">default
{
    state_entry()
    {
        integer rootLinkNum = !!llGetLinkNumber();
        // returns 0 in an unlinked prim, 1 in a linkset
 
        integer isFullBright = llList2Integer(llGetLinkPrimitiveParams(rootLinkNum,[PRIM_FULLBRIGHT, ALL_SIDES]),0);
        // TRUE if all sides of an unlinked prim or the root of a linkset are set to full bright, FALSE otherwise
    }
}</source>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llGetKey]]}}
|also_functions={{LSL DefineRow||[[llGetKey]]}}

Latest revision as of 15:57, 25 August 2018

Summary

Function: integer llGetLinkNumber( );

Returns an integer that is the link number of the prim containing the script.

0 means the prim is not linked, 1 the prim is the root, 2 the prim is the first child, etc. Links are numbered in the reverse order in which they were linked -- if you select a box, a sphere and a cylinder in that order, then link them, the cylinder is 1, the sphere is 2 and the box is 3. The last selected prim has the lowest link number.

Caveats

  • By design may equal llGetNumberOfPrims, e.g., when prim is last, object contains multiple prims, and no sitting avatars
All Issues ~ Search JIRA for related Bugs

Examples

default
{
    state_entry()
    {
        llOwnerSay((string) llGetLinkNumber());
        llOwnerSay((string) llGetNumberOfPrims());
    }
}

A non-obvious feature is using double-negation to obtain a link number zero (for an unlinked prim) or one (for the root of a linkset). Unlike constants like LINK_ROOT, this number can be used directly with functions like llGetLinkPrimitiveParams without first determining whether a prim is part of a linkset:

default
{
    state_entry()
    {
        integer rootLinkNum = !!llGetLinkNumber();
        // returns 0 in an unlinked prim, 1 in a linkset

        integer isFullBright = llList2Integer(llGetLinkPrimitiveParams(rootLinkNum,[PRIM_FULLBRIGHT, ALL_SIDES]),0);
        // TRUE if all sides of an unlinked prim or the root of a linkset are set to full bright, FALSE otherwise
    }
}

See Also

Functions

•  llGetKey
•  llGetNumberOfPrims

Deep Notes

Search JIRA for related Issues

Signature

function integer llGetLinkNumber();