|
RacerX Gullwing
Magic Rabbit
Join date: 18 Jun 2004
Posts: 371
|
06-26-2008 22:33
simplified this as much as I could. I'm trying to make a float named num6 that equals -0.05; be able to be reassembled on the fly and from the string num and a number 6 ex: "num"+"6" and be able to use it for the float worth -0.05 again. it keeps coming back as worth 0 which makes me think it's
Is this possible.
float num0 =0.55; float num1 =0.45; float num2 =0.35; float num3 =0.25; float num4 =0.15; float num5 =0.05; float num6 =-0.05; float num7 =-0.15; float num8 =-0.25; float num9 =-0.35; string newstring; update_totals() { string total_calS= (string)7654; integer calthou =(integer)llGetSubString(total_calS,0,0); string calhun =llGetSubString(total_calS,1,1); string calten =llGetSubString(total_calS,2,2); string calone =llGetSubString(total_calS,3,3); llSay(0,"num"+calhun); newstring = "num"+calhun; llSay(0,newstring); float tofloat =(float)newstring; float number= 0.1 + tofloat; llSay(0,(string)number); llSetLinkPrimitiveParams(0,[ PRIM_TEXTURE, 2,"a27a711d-e8ad-a572-266a-3f973e06ea61",<0.9,0.1,0>,<0,(number),0>,0]); } default { state_entry() {
update_totals(); }
}
|
|
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
|
06-26-2008 23:38
What you are trying to do is not possible in LSL.
You cannot evaluate string values to variable names in LSL.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
06-26-2008 23:42
No, not possible. What you are trying to do is essentially reflection, which requires that the program/system remembers the name you used for the variable and allows some means for you to index it using that name. LSL does not do this. In fact, once the code is compiled the variable might as well be named alksdjfcowiajrxoweisnuffleitis for all SL cares. So the only way you could conceivably do this is by hard-coding your own logic, like: float lookup(string varName) { if (varName == "num1") { return num1; } else if (varName == "num2") { return num2; } else if (varName == "num3") { return num3; } // etc. }
|
|
Viktoria Dovgal
…
Join date: 29 Jul 2007
Posts: 3,593
|
06-26-2008 23:54
Is your real problem just that you want to map those digits to values? If you skip the whole "num" prefix thing, you might instead put the numbers into a list and use that digit as your index.
|
|
RacerX Gullwing
Magic Rabbit
Join date: 18 Jun 2004
Posts: 371
|
06-27-2008 00:46
Yes doing the else if thing now. Thanks new there was a reason I couldn't make that work. If the numbers were the same as the offsets I could do it directly.
|
|
Viktoria Dovgal
…
Join date: 29 Jul 2007
Posts: 3,593
|
06-27-2008 00:58
From: RacerX Gullwing If the numbers were the same as the offsets I could do it directly. Right, that's exactly the kinds of things lists are for. If you keep stuff you need to look up in separate variables, you'll only get frustrated. list magicnumbers = [ 0.55, // 0 0.45, // 1 0.35, // 2 0.25, // 3 0.15, // 4 0.05, // 5 0.05, // 6 0.15, // 7 0.25, // 8 0.35 // 9 ];
update_totals() { string total_calS= (string)7654; if (llStringLength(total_calS) != 4) { llSay(0,"oops, wrong size"); return; } integer calthou =(integer)llGetSubString(total_calS,0,0); string calhun =llGetSubString(total_calS,1,1); string calten =llGetSubString(total_calS,2,2); string calone =llGetSubString(total_calS,3,3);
llSay(0,"num " + calhun); if (llSubStringIndex("0123456789", calhun) == -1) { llSay(0,"oops, not a digit"); return; }
float tofloat = llList2Float(magicnumbers, (integer)calhun); float number= 0.1 + tofloat; llSay(0,"number " + (string)number); llSetLinkPrimitiveParams(0,[ PRIM_TEXTURE, 2,"a27a711d-e8ad-a572-266a-3f973e06ea61",<0.9,0.1,0>,<0,(number),0>,0]); } default { state_entry() { update_totals(); } }
|
|
RacerX Gullwing
Magic Rabbit
Join date: 18 Jun 2004
Posts: 371
|
06-27-2008 01:39
ah there it is that's great ty and before I got to far into that nightmare of else ifs.
|