Manually populating arrays?

I’m trying to manually populate a 2D array to I can easily switch between color themes and patterns, but I can’t figure out how to do that for some weird reason. I’ve tried a few different syntaxes. I can create a function to populate a 1D array and call that function over and over with new values, but going to a 2D array seems to break everything.

It would be really nice if I could just write an array like this:
themes = [[a,b,c],[a,b,c],[a,b,c]]

Then access it like:
stuff = themes[0][2]

Is this possible with the PIxelblaze IDE?

Hey John,

[Edit: as of Oct '21’s firmware v3.2 and 2.28, array literals are now supported!]

Array literals aren’t yet supported. Wizard (Ben) said it makes memory management harder and would require implementing a garbage collector.

So, to populate a 3x3, I would do this:

themes = array(3)
for (i = 0; i < 3; i++) themes[i] = array(3)
themes[0][0] = a
themes[0][1] = b
// etc

Sometimes I write a helper to let me to set a row compactly with arguments separated by commas.

assignRow3Col = (arr, r, c0, c1, c2) => { arr[r][0] = c0; arr[r][1] = c1; arr[r][2] = c2 }
assignRow3Col(themes, 0, a, b, c)


assign3 = (c0, c1, c2) => { 
  arr = array(3)
  arr[0] = c0; arr[1] = c1; arr[2] = c2
  return arr 
themes[0] = assign3(a, b, c)

When I need to “manually” set large arrays in pixelblaze, I’ve been using a spreadsheet to manipulate and store all the data in, then use a CONCAT() fuction to create a column with
lots of array assignments like
big_array[0][0] = 4
big_array[0][1] = 2
big_array[0][2] = 3

then, just copy the column, and paste it into my code.

1 Like

I was able to remove the matrix array in the end, I had for the RYB code, and hard code the values, but I did it the long way first, and fleshed out the matrix, and yes, it’s annoying to have one line per element, plus a loop for setup. Consider this to be a pain point, still, @wizard in using arrays. A shortcut, if not just literals, would be nice.