Variables may be put into arrays, which allows you to group data of the same kind together. Arrays can only have constant sizes, and can only be declared in global scope (outside of functions in system VC code.)
int numbers[15]; // Makes a list of 15 integers str names[7]; // This one is a list of 7 strings // The following is illegal: int foo = 17; // Verge does not allow this, because foo is a variable, not a constant. int illegal[foo]; // However, using a define will work out expected: #define FOO 17 // This is allowed, because FOO is 17 and won't change. int legal[FOO];
Arrays are defined with the number of elements that they contain, but when accessing the elements you start counting with 0. So if you have 15 elements, they are numbered 0 through 14.
Once you've declared an array, you can set the elements of that array inside a function. So, using the above example (with numbers[15] declared), we can do stuff like this:
// This sets the first member of 'numbers' to 42. numbers[0] = 42; // This sets the last member of 'numbers' to 3. numbers[14] = 3; // The following line will do very very bad things // because it is setting data outside of an array's bounds. // A negative index is always outside of an array numbers[-1] = 3; // Likewise any index >= size of the array is invalid. numbers[10000] = 123;
Note that the VC compiler can't check if an array access will be invalid ahead of time, so it will either cause runtime errors or fail silently. Therefore, you need to be careful to ensure you only access valid indexes of the array, or horrible things happen.
Arrays can also be created in multiple dimensions:
// This creates a 2-dimensional array of ints int mock_screen[320][240]; // This creates a 3-dimensional array of strings. string goats[100][100][100]; // This makes a 10-dimensional array of ints. // making a multi-dim array this big is stupid, // but possible. int tacos[5][4][17][22][79][34][11][19][7000][2];
This is how you assign elements inside of a multi-dimensional array.
// This sets element 0,0 of the array to 12 mock_screen[0][0] = 12; // This sets element 123,79 of the array to 43 mock_screen[123][79] = 43; // This sets element 0,41,12 of this array to "Toothgnip". goats[0][41][12] = "Toothgnip";
You cannot set an array instance equal to another array instance. You may only set array elements. To wit, this won't work:
int list_a[100]; int list_b[100]; void AutoExec() { list_a = list_b; // Won't work! }
So to get around this, you might consider using a for loop and copying items piecewise:
int i; for(i = 0; i < 100; i++) { list_a[i] = list_b[i]; }