Script efficiency help, please
|
|
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
|
07-08-2009 16:57
A project I'm working on has some of the problems discussed in an earlier thread. /54/ca/314543/1.htmlMy project is an animated walking thing in which one of four sets of legs are visible at a time. Each leg is composed of 5 prims. I'm using individual scripts in all the leg prims to set alpha in the right sequence using llmessagelinked, which is a no-no according to the above thread. The suggestion in the thread above is to create a list of the prim names and then use the index number of each prim in the root script. How would that preserve the correct prim reference if the link numbers of the prims changes? The list index would no longer correspond to the link number. Do I have to regenerate the list every time the object is rezzed or changed? Is there a way to apply llSetLinkAlpha to all prims in the list that are named "leg", for example? Second question - are trig functions particularly slow? I had to use llasin to calculate a turn angle, and as soon as I added that function it seemed like the script slowed down drastically.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-08-2009 19:58
From: Galena Qi A project I'm working on has some of the problems discussed in an earlier thread. /54/ca/314543/1.htmlMy project is an animated walking thing in which one of four sets of legs are visible at a time. Each leg is composed of 5 prims. I'm using individual scripts in all the leg prims to set alpha in the right sequence using llmessagelinked, which is a no-no according to the above thread. The suggestion in the thread above is to create a list of the prim names and then use the index number of each prim in the root script. How would that preserve the correct prim reference if the link numbers of the prims changes? The list index would no longer correspond to the link number. Do I have to regenerate the list every time the object is rezzed or changed? Is there a way to apply llSetLinkAlpha to all prims in the list that are named "leg", for example? Second question - are trig functions particularly slow? I had to use llasin to calculate a turn angle, and as soon as I added that function it seemed like the script slowed down drastically. dunno about your trig function problem, but the math functions from what I've seen are plenty fast so it's probably something else... as to the first problem, you can preload the names and prim numbers and only check up on them if you get a changed event with CHANGED_LINK... what you do is look for specially named prims, then pair them with their link number, you can optionally sort them, or look for the correct pair for your sequence when you are looping through your set alpha calls (since alpha has no built in delay you are pretty safe calling it 5 times in a row for each leg part) unfortunately set Link is a mostly all or nothing function... you can call it LINK_SET, or LINK_ALL_OTHERS, or LINK_ALL_CHILDREN to get multiples... but that's about it.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
|
07-11-2009 09:28
I need a bit more help with this. My build has a lot of prims (100 and growing), and it seems like a list of all of those names would clutter up my script. Could I read them from a notecard? Also, I don't know how to pair the prim names with the prim numbers. Do I keep two lists and step through them in sequence? How do I reference a particular index number in a list?
Would it work to search for specific prim names every time I need them using llGetLinkName(llGetLinkNumber(i)); rather than keep them in a list? Or would this be too slow?
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-11-2009 11:02
a basic name to prim number function in 4 categories list gLstTgt = ["FL", "FR", "BL", "BR"]; //-- FRONT/BACK LEFT/RIGHT list gLstFL; list gLstFR; list gLstBL; list gLstBR;
uUpdateTargets(){ gLstFL = gLstFR = gLstBL = gLstBR = []; list vLstTgt; integer vIntTst; integer vIntCnt = llGetNumberOfPrims(); do{ vLstTgt = (list)llGetLinkName( vIntCnt ); if (~(vIntTst = llListFindList( gLstTgt, vLstTgt ))){ if (2 & vIntTst){ if (1 & vIntTst){ gLstBR += vIntCnt; } else{ gLstBL += vIntCnt; } } else if (1 & vIntTst){ gLstFR += vIntCnt; } else{ gLstFL += vIntCnt; } } }while (vIntCnt--); }
all prim numbers for prims named FL will be in the list gLstFL, which you can loop through... you would call this function on state entry, and probably CHANGED_LINK (although dealing with sitting avs may be an issue) ETA: yes I could've gone with --vIntCnt, and yes it does the loop one extra time ... a drawback of the goofy numbering change that occurs between single and multi prim objects, this will catch all prims both types of object
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
|
07-11-2009 12:52
Great, thanks!
I'm still learning LSL and like to understand the scripts I use. Basic question about the loop part of the code, which conceptually is:
do
LstTgt = (list)llGetLinkName( vIntCnt );
...go through each list up to the max no. prims (vIntCnt)
}while (vIntCnt--);
In this while statement, what value of vIntCnt will be evaluated as "false" in order to stop the loop? It appears to me that vIntCnt will continue to decrement indefinitely.
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
07-11-2009 13:14
In LSL, 0 evaluates as FALSE, anything non-zero evaluates as TRUE. When vIntCnt decrements to zero, the loop stops. Void's note, referring to vIntCnt-- versus --vIntCnt, refers to when vIntCnt is decremented. As written, it decrements after its current value is evaluated, so the do loop executes one extra time.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-11-2009 20:27
instead of starting at the root and going through all the prims up to a cap, we start at the cap, and go down to zero, which makes the test easier (we don't have to compare it, just check if it went to zero...don't do this with floats*).
the oddity in LSL is that if an object has only one prim (the root) it's numbered 0, but if it has more than one prim then the numbering starts at 1 (for the root) so we need to catch both possibilities since number of prims will either be the last numbered prim in multiprim objects, or one higher in single prime object
(the point is kinda moot if you are using multiple categories, you SHOULD have multiple prims, but this is just a safety catch for testing)
to add to what Rolig said, that action of --x is "subtract one from x and use the new number" the action of x-- is "use x then subtract one after it's used"
*unless you are ABSOLUTELY sure the value of the float is actually going to be a whole number, or you may end up with a number that is fractionally off and won't become 0.0, which will give you an infinite loop
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
|
07-12-2009 09:29
From: Galena Qi A project I'm working on has some of the problems discussed in an earlier thread. /54/ca/314543/1.htmlMy project is an animated walking thing in which one of four sets of legs are visible at a time. Each leg is composed of 5 prims. I'm using individual scripts in all the leg prims to set alpha in the right sequence using llmessagelinked, which is a no-no according to the above thread. . It's only a no-no if you're talking about a 250 prim animal. If the lets are only a few prims, it's fine. The technique is good. Using 250 scripts to achieve it is the bad part. However, many items in SL do this, by necessity. Remember, there is no absolute wrong in SL.
|
|
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
|
07-12-2009 16:44
Is 20 scripts using llmessagelinked too many? I'm struggling with lists and my "thing" works perfectly right now. I was suffering lag-inducing guilt pangs, but will gladly shelve this if it isn't a big deal.
Last question about lists, though - is it possible to store names of lists within a list, then convert these strings to a variable name? In Void's example above, I would like to be able to create a list like this:
list vFrame = ["gLstFL", "gLstFR", "gLstBL","gLstBR "];
If I could strip the quotation marks off these string values, I could use them to reference the global list variables in a loop.
Thanks to all you scriptizens for your advice!
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-12-2009 19:48
From: Galena Qi Is 20 scripts using llmessagelinked too many? I'm struggling with lists and my "thing" works perfectly right now. I was suffering lag-inducing guilt pangs, but will gladly shelve this if it isn't a big deal.
Last question about lists, though - is it possible to store names of lists within a list, then convert these strings to a variable name? In Void's example above, I would like to be able to create a list like this:
list vFrame = ["gLstFL", "gLstFR", "gLstBL","gLstBR "];
If I could strip the quotation marks off these string values, I could use them to reference the global list variables in a loop.
Thanks to all you scriptizens for your advice! unfortunately, no... the closest you can get is using llListFindList or a comparison to get the name from your master list, and use that as a selector for addressing your other list kinda like integer vIntTst = llListFindList( vFrame, (list)some_string_to_match ); if (vIntTst == 0){ //do something with gLstFL } else //etc ETA: the benefit of building the list style into your main script (or even using link targeting with llSetLibnkPrimitiveParams) is that when you go to update/edit the object you don't have to hunt for multiple scripts in different prims, which makes the whole process so much easier
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|