Almost there, actually I can work around this, but it's not perfect, so I'm going to throw it out there:
Compare this code
# Statically defined array, working properly
{
:local testArray {11=1; 12=1; 21=1; 22=1}
:local testRows 2
:local testCols 2
:local testRowSize 10
:put $testArray
:for x from=1 to=$testRows step=1 do={
:for y from=1 to=$testCols step=1 do={
:local value ($testArray->[:tostr (($testRowSize * $x) + $y)])
:put ("Type of row $x column $y is $[:typeof $value] with value $value")
}
}
}
Which outputs this:
11=1;12=1;21=1;22=1
Type of row 1 column 1 is num with value 1
Type of row 1 column 2 is num with value 1
Type of row 2 column 1 is num with value 1
Type of row 2 column 2 is num with value 1
To this code which builds the array dynamically
# Dynamically defined array based on the above static array
{
:local testRows 2
:local testCols 2
:local testRowSize 10
:local testArray
:for x from=1 to=$testRows step=1 do={
:for y from=1 to=$testCols step=1 do={
# :put $testArray
:local coord (($testRowSize * $x) + $y)
:if (($x = 1) and ($y = 1)) do={ \
:set testArray {11=1}
} else={ \
:set ($testArray->[:tostr $coord]) 1
}
}
}
:put $testArray
:for x from=1 to=$testRows step=1 do={
:for y from=1 to=$testCols step=1 do={
:local value ($testArray->[:tostr (($testRowSize * $x) + $y)])
:put ("Type of row $x column $y is $[:typeof $value] with value $value")
}
}
}
And outputs this:
11=1;12=1;21=1;22=1
Type of row 1 column 1 is num with value 1
Type of row 1 column 2 is num with value 1
Type of row 2 column 1 is num with value 1
Type of row 2 column 2 is num with value 1
I've got to use an ugly kludge to start the array, since RouterOS won't let me use variables in a :set statement for an array
:if (($x = 1) and ($y = 1)) do={ \
:set testArray {11=1}
else={ \
:set ($testArray->[:tostr $coord]) 1
}
Is this a shortcoming in the language, or am I an idiot?