Jump to content
Sign in to follow this  
Jamie Monacular

Determining the link number of a named prim....

Recommended Posts

I'm trying to figure out an efficient way to go about getting the link number of a named prim within a linkset when only the name of said prim is known and there is no touch happening (script is getting the prim names via a listen or link_message depending on the situation).

I've tried keeping a list of the link numbers, but as the build gets modified and new prims added or old ones taken away, that becomes more and more difficult to do.

Any ideas or suggestions?

  • Like 1

Share this post


Link to post
Share on other sites

In my own projects I just iterate, if the call isn't happening too often.

If it is a common occurence, I'd keep a list with names and recreate the list if the linkset changes.

Share this post


Link to post
Share on other sites

 

if (change & CHANGED_LINK){    gPrimnames = [];    integer i;    for(i=1;i<=llGetNumberOfPrims();++i)    {       gPrimnames += [llGetLinkName(i)];    }}

 Then you can safely query the global list gPrimnames by list index at any time with

integer LinkIdx = llListFindList(gPrimnames, [the_link_I_Want]) + 1;

to get the number of a named link.

 

  • Thanks 1

Share this post


Link to post
Share on other sites

if the link message is coming from the named prim you get it for free in the first integer. ...

 

if the named prim will be unique in the set, then it's easy enough to save all of the link names to a single list, in order, use list find list, and add one to the result. when the changed event fires with CHANGED_LINK you can clear the list and redo it. (*as Rolig demonstrated)

if you need to target multiple prims of the same name, but only need to worry about a single name, you can do the same thing.

if you have multiple names, with multiple targets each, my approach has been to record a name, count, and indexes...  the count tells you both how many prims of that name, and how many entries before you get to the next set of names,

although you can cheat and record the name, and insert any link numbers in front of it, when checking the list subtract 1 and check if it's a number, if it is, it's a link named to your target, repeat until you counter falls below zero, or you find a text list item.

ETA:
*Must learn to type faster

Share this post


Link to post
Share on other sites

 

integer getLinkNum(string primName){    integer primCount = llGetNumberOfPrims();    integer i;    for (i=0; i<primCount+1;i++)    {        if (llGetLinkName(i)==primName) return i;    }    return FALSE;}

 

Found the solution to what I was trying to do elsewhere. There it is above in case it's of use to anybody else.

 

Share this post


Link to post
Share on other sites

Nice.  As usual in scripting, there's more than one solution to a problem. If you only need to use the function a couple of times, this one's a good solution. Each use involves querying every single prim in the linkset, though, so if you have to use this function very many times, it ends up doing way too much computation. In that case, it's smarter to query the prims one time and save the results in a list. Checking the list for an index is much faster in the end. One of the challenges in scripting is to find the best solution for the particular situation you are facing.  Not always easy. :smileytongue:

Share this post


Link to post
Share on other sites

I use something similar to the 'getLinkNum' function.....along with a couple of variations (that use llGetSubString) to match based on the prim name starting with or ending with a certain string, and returning a list of all matching prim numbers.

 

 

list GetLinkNumsByStart(string s){
 integer i; list t = []; for(i=0; i < llGetNumberOfPrims(); ++i)
if(llGetSubString(llGetLinkName(i),0,llStringLength(s)-1) == s) t+=[i]; return t;}

 

 

 

The GetLinkNumsByEnd(string s) function is the same, only it uses indexes on the llGetSubString() from -(llStringLength(s)) to -1.

 

With careful naming of prims, you can easily control whole sets pretty easily.  And you only have to run the functions once (unless you are linking/unlinking prims in script too....) after rez to fill in the lists.  It works for full names too, but you have to pull out the single list element (an extra step, if you don't need the list capability.)

 

Share this post


Link to post
Share on other sites

This is the closest thread I could find regarding what I am trying to do (my scripting skills are pretty basic).  I am using the follwing script to change the alpha setting on all walls in a linkset.  I would like to be able to do if prim name is WALL change alphs, if prim name is BEAM change alpha and light settings.  The goal is to turn lights on and off, and show a shaded texture (or not) on the walls.  The script below already changes the wall texture.

 

float alphstate0 = 1.0;float alphstate1 = 0.0;float time = 0.0;  integer currentstate;switch(float alph){    llSetLinkAlpha(LINK_SET, alph, ALL_SIDES);    currentstate = ~currentstate;    llSleep(time);}default{    touch_start(integer total_number)    {        if(currentstate)            switch(alphstate0);        else            switch(alphstate1);    }}

 Any thoughts? Or am I asking too much of one script?

 

Share this post


Link to post
Share on other sites

Not at all, you can use one of the methods listed above to iterate through the links and then check if the name returned is equal to your specific names, and then do those functions on that link.

Share this post


Link to post
Share on other sites


Freyr Darkstone wrote:

there's a way to use the number we find to set a texture on that precise prim in the linkset?

Holy cow this is an ancient thread !

Sure, call llSetLinkPrimitiveParamsFast(), using that number to specify the link on which to operate, and the PRIM_TEXTURE flag for the rule to set the texture.

Or, if setting the texture to a single link in the linkset is really all you want to do, you can use llSetLinkTexture() instead.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...