I'll start from the bottom, skip ahead until you reach the part that's causing you problems. :)

Coming from a more low-level programming background, I find it sometimes helps to think of these things as arrays containing arrays containing arrays, rather than something that has multiple dimensions.

So, a two dimensional array of integers can be thought of as an array where each element of the array is an array containing integers. So this:

int a[2][3];

is one array (a) containing two arrays (a[0] and a[1]) who, in turn, contain three integers each. All integers in a[0] and a[1] are initialized to zero by ChucK.

If we want to add another integer array so that the size becomes a[3][3], we can do that like this, using ChucK's push operator for adding elements at the end of an array:

a << [4,5,6];

Now there's a third array a[2], which contains the numbers 4, 5 and 6. a[0] and a[1] still both contain 0, 0, 0.

If we now want to add a third dimension, we'll be dealing with an array that contains arrays that in turn contain arrays of integers:

int q[0][3][3];

This new array is as of yet empty, since it was initialized with zero in the first size placeholder. We can make that size 1 by running this (using our previous array a):

q << a;

The size of q is now as if we had initialized it like this:

int q[1][3][3];

...though if we had initialized it like that it would be all zeroes, now it contains one "frame" (from your example) with the numbers that we put in a before.

I made some code to test that what I said above checked out, including it below. Hope this helps!

// now, the size of "cel" is [2][16][8]
// if the button is pressed again, it becomes [3][16][8]

interestingly, if i declare newframe at the start of the program, (after int cel, before if), cel will still expand, but not with unique data. in other words, you can add 9 frames, but frames 2-10 will all be identical. edits to frame 3 also change 2, 4, 5, etc. instantiating newframe every time the button is pressed seemed to fix that.

inside a block (i.e. some code that is enclosed within curly brackets, like the contents of your if statement or a function) will cause a new array to be created each time you enter that block, which is also inaccessible outside the block. If you write the same thing at root level - i.e. not enclosed by any curly brackets at all - it becomes a global variable that is initialized when the program starts, and stays the same throughout the program's life length.

This is different from, say, javascript (if you've hacked some of that), where a variable declared anywhere (with "var" in front of it) is available to either the whole function it was declared in, or if was declared outside a function, the whole program._________________Antimon's Window@soundcloud@Flattrhome - you can't explain music

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum

Please support our site. If you click through and buy from our affiliate partners, we earn a small commission.