Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Referencing Variables

Indyjoe Rinkitink
Registered User
Join date: 7 Apr 2006
Posts: 6
01-12-2007 12:57
Not the most experienced scripter and was wondering if someone could help me out.

Have a list of variable

float Var1;
float Var2;
float Var3;
float Var4;

(these are the literal names)

How can I do assignments without if/else queries?

For instance I'd like to do something like

integer x=1;

float final_var;

final_var is assigned the value of variable named "Var"+(string)x

I know I can do it with if/else, but is there any way to do a direct dynamic assignment?

Hope my question is clear as mud.
Any assistance is much appreciated.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-12-2007 13:25
From: Indyjoe Rinkitink
Not the most experienced scripter and was wondering if someone could help me out.

Have a list of variable

float Var1;
float Var2;
float Var3;
float Var4;

(these are the literal names)

How can I do assignments without if/else queries?

For instance I'd like to do something like

integer x=1;

float final_var;

final_var is assigned the value of variable named "Var"+(string)x

I know I can do it with if/else, but is there any way to do a direct dynamic assignment?

Hope my question is clear as mud.
Any assistance is much appreciated.


Afraid not, at least not as you have it there.
You are talking about arrays which LSL does not directly support.
What you could do is use a list and then access the list by index

(Noddy Example)

CODE

float Var1 = 10.0;
float Var2 = 20.0;
float Var3 = 30.0;
float Var4 = 40.0;

float GetVar(integer x)
{
float retval = 0.0;
if((x > 0) && ( x < 4))
{
list vars = [ Var1, var2, Var3, var4 ];
retval = llList2Float(vars, x - 1);
}
return retval;
}

default
{
state_entry()
{
integer x = 3;
float Value = GetVar(x);
}
}
Indyjoe Rinkitink
Registered User
Join date: 7 Apr 2006
Posts: 6
01-12-2007 13:45
That's kind of what I thought, unfortunately, the variables I was thinking of using might end up being lists themselves so your method would involve lists of lists.

:-(
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-12-2007 14:54
From: Indyjoe Rinkitink
That's kind of what I thought, unfortunately, the variables I was thinking of using might end up being lists themselves so your method would involve lists of lists.

:-(


Well you have a limit of 16K for both code and data per script so you will need to be efficient in how you do it.

Lists of lists are possible but you need to be careful about indexing