Altier Verwood Posted September 15, 2021 Share Posted September 15, 2021 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 More sharing options...
bobsknief Orsini Posted September 15, 2021 Share Posted September 15, 2021 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]); 1 Link to comment Share on other sites More sharing options...
KT Kingsley Posted September 15, 2021 Share Posted September 15, 2021 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). 1 1 Link to comment Share on other sites More sharing options...
Altier Verwood Posted September 15, 2021 Author Share Posted September 15, 2021 You are amazing thank you so much, something so small held up the whole script XD it compiled! 1 Link to comment Share on other sites More sharing options...
Altier Verwood Posted September 15, 2021 Author Share Posted September 15, 2021 One more, thing its along the same lines, is there a way I can make my integer here. integer hp = 500; read object description like this integer hp = llGetObjectDesc(); ? Link to comment Share on other sites More sharing options...
Mollymews Posted September 15, 2021 Share Posted September 15, 2021 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 More sharing options...
Altier Verwood Posted September 15, 2021 Author Share Posted September 15, 2021 Hm when i tried that it gives me a syntex error, but i don't see what im doing wrong. integer hp = (integer)llGetObjectDesc(); Link to comment Share on other sites More sharing options...
Altier Verwood Posted September 15, 2021 Author Share Posted September 15, 2021 Never mind, I put the integer in the wrong spot XD 1 Link to comment Share on other sites More sharing options...
Mollymews Posted September 15, 2021 Share Posted September 15, 2021 (edited) the wiki page that details typecasting is here: http://wiki.secondlife.com/wiki/Typecast Edited September 15, 2021 by Mollymews Link to comment Share on other sites More sharing options...
Rolig Loon Posted September 15, 2021 Share Posted September 15, 2021 Returning to your original question, you could have also used llSubStringIndex in your procedure, as in if ( llSubStringIndex( llGetLinkName(x), "Fire") != -1) { return x; } Link to comment Share on other sites More sharing options...
Quistess Alpha Posted September 15, 2021 Share Posted September 15, 2021 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 More sharing options...
Altier Verwood Posted September 15, 2021 Author Share Posted September 15, 2021 WHoa, that looks way over kill to what I have my script doing XD Link to comment Share on other sites More sharing options...
bobsknief Orsini Posted September 16, 2021 Share Posted September 16, 2021 For good measure, unsure if you let people edit it, as they love putting spaces all over the place. Always trim off the spaces: llStringTrim(llGetObjectDesc(), STRING_TRIM) 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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