# llGetLinkNumber

*LSL function*

```lsl
integer integer llGetLinkNumber();
```

- Returns: `integer`
- Energy: 10

`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.

Returns an [integer](https://wiki.secondlife.com/wiki/integer) that is the link number of the prim containing the script.

```lsl title="How to use" frame="terminal"
integer result = llGetLinkNumber();
```

## Caveats

- By design may equal [llGetNumberOfPrims](/functions/llGetNumberOfPrims/), *e.g.*, when prim is last, object contains multiple prims, and no sitting avatars

## Examples

<details open>
<summary>Example 1</summary>

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

</details>

<details>
<summary>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](/constants/LINK_ROOT/), this number can be used directly with functions like [llGetLinkPrimitiveParams](/functions/llGetLinkPrimitiveParams/) without first determining whether a prim is part of a linkset:</summary>

```lsl
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
    }
}
```

</details>

## See also

### Functions

- [llGetKey](/functions/llGetKey/)
- [llGetNumberOfPrims](/functions/llGetNumberOfPrims/)

---

*Source: [LlGetLinkNumber](https://wiki.secondlife.com/wiki/LlGetLinkNumber) on the Second Life Wiki. Content from the Second Life Wiki article LlGetLinkNumber (revision 1207456, 2018-08-25), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llGetLinkNumber/
