variable variable names
alan.heric
Posts: 18
Hello,
was wondering if there is option to make variable variable names in netlinx?
What i have in mind is like you have option in php to change the variable name...
Example:
if i have 3 variables named room1,room2,room3
and i want to put same value in them in lets say a for loop.
this is what it would look like in php:
for ($i=1;$i<=10;$i++)
{
${"room".$i)='some value';
}
is this possible in netlinx or not
tnx
was wondering if there is option to make variable variable names in netlinx?
What i have in mind is like you have option in php to change the variable name...
Example:
if i have 3 variables named room1,room2,room3
and i want to put same value in them in lets say a for loop.
this is what it would look like in php:
for ($i=1;$i<=10;$i++)
{
${"room".$i)='some value';
}
is this possible in netlinx or not
tnx
0
Comments
You can use an array of variable
char Room[3][20]
local_var integer i
for(i=1;i<=3;i++)
{
room = 'some value'
}
but tnx for your answer
Array will work as stated above, but structures are cleaner and allow you to store a lot more info in 1 place.
For example:
Here we track 10 rooms with names, volume, state, source, etc.
Upon startup we will initialize the structure with all rooms off and volume at zero (not something you would do in the real world I know).
We also set the room names for each room because it is volatile in this example (again not practical in the real world).
I think you will find this a lot easier than keeping a whole mess of individual typed variable for every room.
** sorry for the huge tab spaces. I don't know why chrome does that when I paste code from NS3 **
That spacing problem is actually the message board's handling of TAB characters. You probably have Studio set up to use a tab stop of 4 characters and the Board's tab stop is 8. So the spacing you see in Studio doubles: </OFF TOPIC>