llGetLinkKey

From Second Life Wiki
Jump to navigation Jump to search

Summary

Function: key llGetLinkKey( integer link_number );

Returns the key of the linked prim link_number

• integer link_number Link number (0: unlinked, 1: root prim, >1: child prims and seated avatars) or a LINK_* flag

Caveats

  • The only LINK_* flag that can be used with link_number is LINK_ROOT.
    • LINK_THIS does not work. ~ SVC-600
    • Since this function only returns a (single) key instead of a list of keys, multi-prim LINK_* flags (LINK_SET, LINK_ALL_OTHERS, and LINK_ALL_CHILDREN) are not accepted by this function (that and this function isn't named llGetLinkKeys or llGetLinkKeyList).
All Issues ~ Search JIRA for related Bugs

Examples

Drag this script on to linked and unlinked prims, with avatars sitting or not, to see how llGetLinkKey relates to llGetKey, llGetLinkNumber, llGetNumberOfPrims, LINK_ROOT, etc. <lsl>// Return the name of a link num else the empty string. string getLinkNumName(integer link) {

   if (LINK_THIS == link) return "LINK_THIS";
   if (LINK_ALL_CHILDREN == link) return "LINK_ALL_CHILDREN";
   if (LINK_ALL_OTHERS == link) return "LINK_ALL_OTHERS";
   if (LINK_SET == link) return "LINK_SET";
   if (LINK_ROOT == link) return "LINK_ROOT";
   return "";

}

// Say the key of each linked prim. default {

   state_entry()
   {
       integer theLink = llGetLinkNumber();
       
       key theLinkKey = llGetKey();
       key owner = llGetOwner();
       key creator = llGetCreator();
       
       // Visit each link num.
       
       integer link;
       integer primmed = llGetNumberOfPrims();
       for (link = -5; link <= (primmed + 5); ++link)
       {
           key linkKey = llGetLinkKey(link);
           
           // Detail the key at the link num.
           
           string line = (string) linkKey; // large constant width
           
           if (linkKey == owner) line += " llGetOwner";
           if (linkKey == creator) line += " llGetCreator";
           if (linkKey == theLinkKey) line += " llGetKey";
           
           // Detail the link num.
           
           line += " @ " + (string) link;
           line += " " + getLinkNumName(link);
           if (link == theLink) line += " llGetLinkNumber";
           if (link == primmed) line += " llGetNumberOfPrims";
           
           // Say the detail if fun.
           
           if (linkKey != NULL_KEY)
           {
               llOwnerSay(line);
           }
       }
       
       // Always count the linked prims.
       
       llOwnerSay((string) primmed + " llGetNumberOfPrims");
       llOwnerSay("OK");
   }
}</lsl>

Notes

Link Numbers

Each prim that makes up an object has an address, a link number. To access a specific prim in the object, the prim's link number must be known. In addition to prims having link numbers, avatars seated upon the object do as well.

  • If an object consists of only one prim, and there are no avatars seated upon it, the (root) prim's link number is zero.
  • However, if the object is made up of multiple prims or there is an avatar seated upon the object, the root prim's link number is one.

When an avatar sits on an object, it is added to the end of the link set and will have the largest link number. In addition to this, while an avatar is seated upon an object, the object is unable to link or unlink prims without unseating all avatars first.

Counting Prims & Avatars

There are two functions of interest when trying to find the number of prims and avatars on an object.

integer GetPrimCount() { //always returns only the number of prims
    if(llGetAttached())//Is it attached?
        return llGetNumberOfPrims();//returns avatars and prims but attachments can't be sat on.
    return llGetObjectPrimCount(llGetKey());//returns only prims but won't work on attachments.
}
See llGetNumberOfPrims for more about counting prims and avatars.

Errata

If a script located in a child prim erroneously attempts to access link 0, it will get or set the property of the linkset's root prim. This bug (BUG-5049) is preserved for broken legacy scripts.

See Also

Functions

•  llGetLinkNumber Returns the link number of the prim the script is in.
•  llGetKey
•  llGetLinkName

Deep Notes

All Issues

~ Search JIRA for related Issues
   llGetLinkKey returns the wrong result when passed LINK_THIS

Signature

function key llGetLinkKey( integer link_number );