Multi-dimensional array bug
-
To demonstrate;
array one[3][6] array two[3][6] for x = 0 to len(one) loop for y = 0 to len(one[x]) loop one[x][y] = rnd(255) repeat repeat loop clear() printAt(0, 0, "one = " + len(one) + " two = " + len(two)) update() repeat
Output is:
one = 6 two = 3
You'd expect the length of both the arrays to still match, right? After all,
one
is being populated correctly and if you view in the data insideone
using 3*6 you can see everything in place ... but ... usinglen(one)
actually returns you "6" and so, if you uselen(one)
again you get a nondescript error ofUnrecognized type: 4
(what in the AMERICAN is this?!?!)My workaround is to process it in rows;
array one[3][6] array two[3][6] for x = 0 to len(one) loop row = [] for y = 0 to len(one[x]) loop row[y] = rnd(255) repeat one[x] = row repeat loop clear() printAt(0, 0, "one = " + len(one) + " two = " + len(two)) update() repeat
-
This is a bug that I already reported and is in the system. In a nutshell the upper bound of the 1st dimension grows to that of the 2nd dimension. In your case the 'two' array hasn't grown because you've not assigned anything to it. Had you done:
one[x][y] = rand(255) two[x][y] = rand(255)
In the main loop then it would have suffered the same fate and they'd both have reported a size of 6 after the print statement.
-
Ah yeah that was there just to demonstrate the "correct" (expected) behaviour! Thank you
-
Has this bug been fixed?
-
Yes in the patch currently under test