LlGetNumberOfPrims: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
Strife Onizuka (talk | contribs)
m Duplicates my GetNumberOfPrims from Febuary 2006 posted on the LSL Wiki, removing the "if" updated it to the August 2007 revision that was posted here.
mNo edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 9: Line 9:
|caveats=*The number of prims returned also includes the number of avatars sitting on the object.
|caveats=*The number of prims returned also includes the number of avatars sitting on the object.
|constants
|constants
|examples=<lsl>default
|examples=<source lang="lsl2">default
{
{
     state_entry()
     state_entry()
Line 16: Line 16:
         llOwnerSay((string)llGetNumberOfPrims());
         llOwnerSay((string)llGetNumberOfPrims());
     }
     }
}</lsl>
}</source>
|helpers=<lsl>
|helpers=<source lang="lsl2">
// Returns the number of prims in the object, ignoring seated avatars
// Returns the number of prims in the object, ignoring seated avatars
integer GetNumberOfPrims()
integer getNumberOfPrims(){
{
  if (llGetObjectPrimCount(llGetKey()) == 0 ) return llGetNumberOfPrims(); // attachment
    if (llGetAttached())
  return llGetObjectPrimCount(llGetKey());   // non-attachment
    {
        // llGetObjectPrimCount fails on attachments, but you can't sit on an attachment
        return llGetNumberOfPrims();
    }
    return llGetObjectPrimCount(llGetKey());
}
}
 
</source>
//-- inline version of the above
(llGetObjectPrimCount( llGetKey() ) + llGetNumberOfPrims() * !!llGetAttached())
 
// Returns the number of agents on the object
integer GetNumberOfAgents()
{
    return llGetNumberOfPrims() - GetNumberOfPrims();
}
 
//-- inline version of the previous
((llGetNumberOfPrims() - llGetObjectPrimCount( llGetKey() )) * !llGetAttached())
</lsl>
This method uses a loop, it is less efficient and only included for completeness. It's more efficient to ask the physics engine (via [[llGetObjectPrimCount]]) how many prims are in the object.
<lsl>
// determine the number of prims in linkset
integer getNumberOfPrims()
{
    integer maxLinkNumber = llGetNumberOfPrims();
    // subtract seated avatars
    while( llGetAgentSize( llGetLinkKey(maxLinkNumber) ) ) {
        --maxLinkNumber;
    }
    return maxLinkNumber;
} // END getNumberOfPrims()
</lsl>
|also_functions=
|also_functions=
{{LSL DefineRow||[[llGetObjectPrimCount]]|Returns the number of prims in any object.}}
{{LSL DefineRow||[[llGetObjectPrimCount]]|Returns the number of prims in any object.}}
Line 62: Line 32:
|notes
|notes
|cat1=Link
|cat1=Link
|cat2
|cat2=Object
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 02:16, 22 January 2015

Summary

Function: integer llGetNumberOfPrims( );
0.0 Forced Delay
10.0 Energy

Returns an integer that is the number of prims in a link set the script is attached to.

Caveats

  • The number of prims returned also includes the number of avatars sitting on the object.

Examples

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

Useful Snippets

// Returns the number of prims in the object, ignoring seated avatars
integer getNumberOfPrims(){
  if (llGetObjectPrimCount(llGetKey()) == 0 ) return llGetNumberOfPrims(); // attachment
  return llGetObjectPrimCount(llGetKey());   // non-attachment
}

See Also

Functions

•  llGetObjectPrimCount Returns the number of prims in any object.
•  llGetLinkNumber Returns the link number of the prim the script is in.

Deep Notes

Signature

function integer llGetNumberOfPrims();