Arrays

It is possible to declare array variables by appending the [] brackets to the type.

When declaring a variable with a type modifier, the type modifier affects the type of all variables in the list. Example:

  int[] a, b, c;

a, b, and c are now arrays of integers.

When declaring arrays it is possible to define the initial size of the array by passing the length as a parameter to the constructor. The elements can also be individually initialized by specifying an initialization list. Example:

  int[] a;           // A zero-length array of integers
  int[] b(3);        // An array of integers with 3 elements
  int[] c(3, 1);     // An array of integers with 3 elements, all set to 1 by default
  int[] d = {,3,4,}; // An array of integers with 4 elements, where
                     // the second and third elements are initialized

Multidimensional arrays are supported as arrays of arrays, for example:

  int[][] a;                // An empty array of arrays of integers
  int[][] b = {{1,2},{3,4}} // A 2 by 2 array with initialized values
  int[][] c(10, int[](10)); // A 10 by 10 array of integers with uninitialized values

Each element in the array is accessed with the indexing operator. The indices are zero based, i.e the range of valid indices are from 0 to length - 1.

  a[0] = some_value;

An array also have two methods. length() allow you to determine how many elements are in the array, and resize() lets you resize the array.


Generated on Tue Nov 2 12:56:02 2010 for AngelScript by  doxygen 1.5.9