Jump to content

llGetNumberOfPrims


Max Pitre
 Share

You are about to reply to a thread that has been inactive for 2977 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

How can I use all the prims in a linkset except the root prim? I'm thinking llGetNumberOfPrims but keep the root prim out of the picture, just not sure how.

Original script

float animation_speed = 0.15;
integer total_prims;
integer link_counter;

default
{
     state_entry()
      {
           total_prims = llGetNumberOfPrims();
            llSetTimerEvent(animation_speed );
             }
              timer()
               { 
               link_counter++; llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); llSetLinkAlpha( link_counter,1.0, ALL_SIDES);
                if( link_counter == total_prims)
 { 
   link_counter = 0;
  }
    }
}

 

 

Link to comment
Share on other sites

Seems a complicated way of just doing this.

float animation_speed = 0.15;integer total_prims;integer link_counter;default{	state_entry()	{		total_prims = llGetNumberOfPrims();		llSetTimerEvent(animation_speed );	}	timer()	{		llSetLinkAlpha(LINK_ALL_CHILDREN, 0.0, ALL_SIDES);		llSetLinkAlpha( link_counter,1.0, ALL_SIDES);		if( link_counter == total_prims)		{			link_counter = 0;		}		link_counter++;	}}
Link to comment
Share on other sites

Yup.  That's another way to do exactly the same thing.  Either one will work.  If you want yet another way, try

float animation_speed = 0.15;integer link_counter;integer total_prims;default{    state_entry()    {        llSetTimerEvent(animation_speed );        total_prims = llGetNumberOfPrims();    }    timer()    {        llSetLinkAlpha(LINK_ALL_CHILDREN, 0.0, ALL_SIDES);        llSetLinkAlpha( ++link_counter%total_prims,1.0, ALL_SIDES);    }}

There are usually several ways to script the same problem.

Link to comment
Share on other sites

As I recall, llGetNumberOfPrims () returns the total number of prims.

Link 0 is reserved for "all prims"

Link 1 is the root prim.

First non-root prim is link #2

So you need a loop that looks more like this (SLIGHT change to previous poster's code):

 

float animation_speed = 0.15;integer link_counter;integer total_prims;default{    state_entry()    {        llSetTimerEvent(animation_speed );        total_prims = llGetNumberOfPrims();    }    timer()    {        llSetLinkAlpha(LINK_ALL_CHILDREN, 0.0, ALL_SIDES);        llSetLinkAlpha( ++link_counter% (total_prims + 1),1.0, ALL_SIDES); // total_prims + 1 is needed in modulus to get the last prim
if (link_counter < 2) // Make sure the prim pointer is neither LINK_SET nor LINK_ROOT
link_counter = 2;
}
}

 

Link to comment
Share on other sites


starverse wrote:

Link 0 is reserved for "all prims"

Nope. Zero is the link number of an unlinked prim. In some functions one can designate all the linked prims with the constant LINK_SET which has a value of -1.

Other LINK-related constants:

 

LINK_ROOT evaluates to 1, but that's only valid on a multiprim linkset.

 

Link to comment
Share on other sites

Ugh. i need more coffee. Still, when sequentially making the different prims appear, the OP said he didn't want the root, so the sequence is (using mathematical notation) [2..llGetNumberOfPrims () ] not [0..llGetNumberOfPrims () - 1] which the modulus function was going to get them.

k % llGetNumberOfPrims () yields 0 to llGetNumberOfPrims () - 1

OP wanted 2 to llGetNumberOfPrims () to be able to cycle through all the children.

I was quibbling with the math, not the program :)

Link to comment
Share on other sites

Exactly right, Steph.  The root prim will always be set to alpha == 0.0 and then immedately to alpha == 1, which is exactly what the OP wants.  Doing it that way does switch the root prim off and on again, but in an imperceptible interval. And it gives you a much simpler code.  :)

Link to comment
Share on other sites

Yup. The OP does want to skip the root prim, which is why the last code I posted uses Steph's suggestion

llSetLinkAlpha(LINK_ALL_CHILDREN, 0.0, ALL_SIDES);

to set only the child prims to alpha = 0.0 in each time step.  The modulus code I wrote switches ALL prims, one at a time, from link ZERO (which does not exist in a linkset) to llGetNumberOfPrims (which is the number of the final prim in the linkset).  I deliberately didn't use

total_prims = llGetNumberOfPrims() - 1;

for that reason.  The only bit of sloppiness on my part is addressing link ZERO in that modulus calculation. As a result, there's a 0.15 second hiccup each time the sequence loops past zero.  I figured that was acceptable (and almosr imperceptible) collateral damage.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2977 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...