variables to call variables

Send us your feedback or ask for features.
analog604
Regular
Posts:262
Joined:29 Dec 2011 15:40
Location:north east, usa
variables to call variables

Post by analog604 » 09 Jan 2012 20:13

Hi guys,

How about being able to use a variable in the construction of a variable name. I use this all the time in other languages, it saves tons of lines of code.

so say we have two structure trees that contain this:

tree1.obj1.x = 10
tree1.obj2.x = 100
tree1.obj3.x = 200

tree2.obj1.x = 400
tree2.obj2.x = 900
tree2.obj3.x = 1200

and we want to copy values from there to a new var for saving parameters for example and set
new default values to the objects. Do it be reference:

decl y,ele;
for(y=1;y<3;y++) {
for(ele=1;ele<4;ele++) {
savethis.tree@{y}.obj@{ele}=tree@{y}.obj@{ele}.x; // like writing savethis.tree1.obj1=tree1.obj1.x in first repetition
tree@{y}.obj@{ele}.x=127; // like writing tree1.obj1.x=127 in first repetition
}
}

The same as:
savethis.tree1.obj1=tree1.obj1.x
savethis.tree1.obj2=tree1.obj2.x
savethis.tree1.obj3=tree1.obj3.x
savethis.tree2.obj1=tree1.obj1.x
savethis.tree2.obj2=tree1.obj2.x
savethis.tree2.obj3=tree1.obj3.x
tree1.obj1.x=127
[...]
tree2.obj3.x=127

which would allow much greater flexibility and ease coding.

Along the same lines, I would very much like to be able to call functions by reference.
decl myobjectFunction=functionName;
@{myobjectFunction}(0);

Done!
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas

Post Reply