Dynamic variable name.. possible?
Posted: 21 Feb 2012, 04:07
Hi,
I'm used to Flash Actionscript2 where you can dynamically refer to a variable.
eg. setting a value in an array.
c1 = new Array(0,0,0,0,0);
x = 1;
eval("c"+x)[2] = 5;
Is anything like this possible in NXC.?
Context: I've written a "Connect 4" game playing robot. The gameboard has 7columns and 6rows. Too many for NXC support for multidimensional arrays (4 max?). So I just created 7 column arrays (c1 - c7) and now I'm running out of memory because I've used so many switch cases to deal with each of these columns, and I haven't even got the robot playing with any smarts yet (It just randomly picks a column for its turn). If I could do something like the above, I could vastly reduce the number of lines of code.
I'm used to Flash Actionscript2 where you can dynamically refer to a variable.
eg. setting a value in an array.
c1 = new Array(0,0,0,0,0);
x = 1;
eval("c"+x)[2] = 5;
Is anything like this possible in NXC.?
Context: I've written a "Connect 4" game playing robot. The gameboard has 7columns and 6rows. Too many for NXC support for multidimensional arrays (4 max?). So I just created 7 column arrays (c1 - c7) and now I'm running out of memory because I've used so many switch cases to deal with each of these columns, and I haven't even got the robot playing with any smarts yet (It just randomly picks a column for its turn). If I could do something like the above, I could vastly reduce the number of lines of code.