Jump to content

enhance counter


testgenord1
 Share

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

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

Recommended Posts

Hi again!
I've made a script that turns childprims from alpha to non-alpha according to their position in the linkset,
starting from the first childprim, going through to the last, and then turn them all alpha again.

What I would like to do is the following:
In order to shorten this process, I would like to have more than one childprim turn non-alpha in one go (here by one touch),
so that childprim 2and3, 4and5, 6and7 ... become non-alpha in one go at the same time.
Which part of the script do I have to change?
Do you maybe have an idea?

I'm posting a simplified version of the script below.
Thank you very much for your help in advance.
 

list lChildprims = [2,3,4,5,6,7,8,9,10,11,12,13,14,15]; //1 is the root prim, which thus remains alpha throughout.
integer iChildprim;
integer total;
integer countChildprims;
integer tick;

default
{
    state_entry()
    {
    llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>,0.0,PRIM_PHANTOM,TRUE]);
    }
        touch_start(integer num)
            {
            total = llGetListLength(lChildprims);
            if (countChildprims >= total) countChildprims = 0;
            integer iChildprim=llList2Integer(lChildprims,countChildprims++);
            llSetLinkPrimitiveParamsFast(iChildprim, [PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 1.0,PRIM_PHANTOM,TRUE]);
            ++tick;
            if (tick > 14)
                {
                    //tick = 0;
                    llResetScript();
                }
            }
}

 

Link to comment
Share on other sites

I've found a work-around myself now, maybe not the most elegant solution, though.
I just split the list into to lists and now the process is started with each of the two shorter lists seperately, thus taking half the time.
If you happen to have a more elegant solution or you have other ideas of improvement, feel free to comment.

list lChildprims = [2,3,4,5,6,7,8]; //1 being the root prim, here remaining alpha throughout. 
list lChildprims1 = [9,10,11,12,13,14,15];

integer iChildprim;
integer total;
integer countChildprims;

integer iChildprim1;
integer total1;
integer countChildprims1;

integer tick;

default
{
    state_entry()
    {
    llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>,0.0,PRIM_PHANTOM,TRUE]);
    }
        touch_start(integer num)
            {
            total = llGetListLength(lChildprims);
            if (countChildprims >= total) countChildprims = 0;
            integer iChildprim=llList2Integer(lChildprims,countChildprims++);
            llSetLinkPrimitiveParamsFast(iChildprim, [PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 1.0,PRIM_PHANTOM,TRUE]);
            
            total1 = llGetListLength(lChildprims1);
            if (countChildprims1 >= total1) countChildprims1 = 0;
            integer iChildprim1=llList2Integer(lChildprims1,countChildprims1++);
            llSetLinkPrimitiveParamsFast(iChildprim1, [PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 1.0,PRIM_PHANTOM,TRUE]);
            
      		++tick;
            if (tick > 14)
                {
                    //tick = 0;
                    llResetScript();
                }
            }
}
Edited by testgenord1
  • Like 1
Link to comment
Share on other sites

Because this is "a simplified version of the script" I'm assuming that it's not really as simple as traversing all the child prims in any order because if it is, there'd be no reason for a list (or lists) of all their link numbers; instead the script could just count from 2 through llGetNumberOfPrims(), setting alpha as it goes along.

Assuming the rest really is as simple as it seems, you don't need a global variable for iChildprim (nor iChildprim1), and indeed that global variable is never used because you already "shadow" that global with another declaration local to the touch_start() handler. (You don't actually need to have even the local variable because you only reference it once, so instead you could just splice the calculation inline where the variable is currently referenced. But keeping the local variable as-is might be handy for printing out debug messages while the script is under development, and might arguably make it easier to read.)

More germane to your actual question: rather than having two separate calls to llSetLinkPrimitiveParamsFast for each touch_start, I'd use the PRIM_LINK_TARGET parameter to get both links at once.

  • Like 1
Link to comment
Share on other sites

Thank you very much for your explanations.
I used them and through trial and error ended up with the following script version, which works.

What I don't understand is the fact that the second version below does not work,
i.e. no matter how you change the numbers (8 and 7 etc.), either one child-prim remains non-alpha,
or all become alpha, but then the script does not reset any more.
Do you maybe have an idea why this is the case?
Thanks in advance.


working version:

//linkset has 14 child-prims + root-prim = 15 prims.
integer i;
integer j;
integer n;

default
{
    state_entry()
    {
    llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>,1.0]);
    }
        touch_start(integer num)
            {
              n= llGetNumberOfPrims();
              i++;
              j--;
             llSetLinkPrimitiveParamsFast(i+1,[PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>,0.0,//1 being the root prim, this starts with first child-prim, 2. 
             PRIM_LINK_TARGET,(n+1)+j, PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>,0.0]);//In order to imply childprim 15, it starts counting downwards from 16.
            
             if (i > 7)  
                {
                    //integer i = 0;
                    llResetScript();
                }
            }
}

 

not-working version:

//linkset has 14 child-prims + root-prim = 15 prims.
integer i;
integer j;

default
{
    state_entry()
    {
    llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>,1.0]);
    }
        touch_start(integer num)
            {
              n= llGetNumberOfPrims();
              i++;
              j++;
             llSetLinkPrimitiveParamsFast(i,[PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>,0.0, 
             PRIM_LINK_TARGET,j+8, PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>,0.0]);
            
             if (i >= 8)  
                {
                 //i = 0;
                  //j = 0;
                    llResetScript();
                }
            }
}

 

Edited by testgenord1
Link to comment
Share on other sites

Well I'm not sure how you got the no-reset behavior, but as written, the second one will start by hiding the root prim (i is 0 when declared, so i++ is 1, or the root). I thought the idea was to do just the child prims, so you could try using i+1 in the call to llSetLinkPrimitiveParamsFast().

If it were me, I'd probably have just one global variable and initialize it in state_entry to llGetNumberOfPrims(), then count down by twos, stopping before it got to 1 (the root). Just in case there's ever an odd number of child prims, I'd check before adding a PRIM_LINK_TARGET of 1 to the parameter list, but if I was sure it'll always be just the same linkset size, that's not necessary.

Edited by Qie Niangao
typo
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1608 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...