Jump to content

Get link number form string?


Altier Verwood
 Share

Recommended Posts

I feel like I learn so much from this forum, I have another question, I'm diving into making my script work more efficiently. I have this snippit here. it scans my link set for a link name, but I need to turn the name it finds back into a link number for the integer to work. could someone shed some light on what I'm doing wrong? thank you so much if anyone gets the time.

 

string name = PART+"Fire";
{
    integer i = llGetNumberOfPrims();
    for (; i >= 0; --i)
    {
        if (llGetLinkName(i) == name)
        {
        keystate = 0 ;
        updateParticles() ;
        llSetLinkPrimitiveParamsFast(name,[PRIM_COLOR,ALL_SIDES,<1.000, 1.000, 1.000>,0.2,PRIM_GLOW,ALL_SIDES,0.8,PRIM_POINT_LIGHT,TRUE,<0.984, 0.752, 0.359>,1,3,.750]);
        }
    } 
}

 

Link to comment
Share on other sites

Here is a easy to use function:

// GET LINK NUMBER WITH NAME
integer getLinkWithName(string name){
    if(llGetLinkNumber() == 0){ // not linked
        return FALSE;
    }
    integer x = llGetNumberOfPrims();
    for(; x >= 0; --x){
        if(llGetLinkName(x) == name){
            return x;
        }         
    }
    return FALSE;
}

Usage:

llSetLinkPrimitiveParamsFast(getLinkWithName(PART+"Fire"),[PRIM_COLOR,ALL_SIDES,<1.000, 1.000, 1.000>,0.2,PRIM_GLOW,ALL_SIDES,0.8,PRIM_POINT_LIGHT,TRUE,<0.984, 0.752, 0.359>,1,3,.750]);   
  • Like 1
Link to comment
Share on other sites

30 minutes ago, Altier Verwood said:

I feel like I learn so much from this forum, I have another question, I'm diving into making my script work more efficiently. I have this snippit here. it scans my link set for a link name, but I need to turn the name it finds back into a link number for the integer to work. could someone shed some light on what I'm doing wrong? thank you so much if anyone gets the time.

 

string name = PART+"Fire";
{
    integer i = llGetNumberOfPrims();
    for (; i >= 0; --i)
    {
        if (llGetLinkName(i) == name)
        {
        keystate = 0 ;
        updateParticles() ;
        llSetLinkPrimitiveParamsFast(name,[PRIM_COLOR,ALL_SIDES,<1.000, 1.000, 1.000>,0.2,PRIM_GLOW,ALL_SIDES,0.8,PRIM_POINT_LIGHT,TRUE,<0.984, 0.752, 0.359>,1,3,.750]);
        }
    } 
}

 

When llGetLinkName(i) matches name, i is the link number of the link called name. So in the call to SLPPF you should use i for the link number parameter (rather than name, which is a string, and won't compile).

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

21 minutes ago, Altier Verwood said:

integer hp = llGetObjectDesc(); ?

cast the returned string as an integer

integer hp = (integer)llGetObjectDesc();

note that the cast will stop at the first non-integer character. For example

hp = (integer)"123A";

hp will be 123

hp = (integer)"A"

hp will be 0

hp = (integer)""

hp will be 0

Link to comment
Share on other sites

A bit off-topic, but as standard operating procedure, in the kind of script that has a lot of llSetLinkPrimitiveParamsFast() calls and such, I usually have some procedure in state_entry to fill up global variables with link numbers. In the (rather common for me) case where you have a lot of things that make sense to put in order, but it's not quite feasible to ensure that they're linked in that order:

list widgets;

list efficientFill(integer n, list fill) // this is overkill.
{   // return a list of fill repeated n times.
    list ret;
    integer bitIndex = 8; // increase to support values of n up to pow(2,bitIndex+1)-1.
    // 0xFF==511 is enough for most use-cases.
    do{
        if(n&(1<<bitIndex))
            ret = ret+ fill;
        ret = ret + ret;
    }while(--bitIndex);
    if(n&(1<<bitIndex))
        ret = ret+ fill;

    return ret;
}

default
{
  state_entry()
  {
    widgets = efficientFill(27,[-1]); // expect 27 widgets. (numbered 0 thru 26)
    integer prim = llGetNumberOfPrims()+1;
    while(--prim)
    {
      // sepparate link name or description into part name and number.
      // there are many ways to do this, just showing one of them
      list parsed = llParseString2List(llGetLinkName(prim),[" "],[]);
      string name = llList2String(parsed,0);
      integer number = (integer)llList2String(parsed,1);
      
      if(llToLower(name)=="widget")
      {
        widgets = llListReplaceList(widgets,[prim],number,number);
      }
    }
    integer unfoundWidget = llListFindList(widgets,[-1]);
    if(unfoundWidget!=-1)
    {
      llOwnerSay("Warning, Widget not found! "+(string)unfoundWidget);
    }
  }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...