myInts int[] = [1,2,3,4,5];In this case, the array is a series of five integer variables. In EGL, the numbering of arrays begins with the number one, so this array has elements numbered one through five.
myInts[1] = 5+5; myInts[2] = 16; myInts[3] = myInts[1] + myInts[2];
myStrings string[2]; myStrings {"Hello", "Goodbye"};
This syntax uses braces ({) and no equals sign (=). This method assigns values to the array as though the elements were its properties. This method offers better performance at run time than the second method, which entails an array literal to the array.
Using a set-value block works only when the array has sufficient elements to accept the new values in braces; EGL does not automatically add more elements. For this reason, you must specify a starting length for the array or add elements to it before you can assign values to elements with a set-value block.
myBigInts bigint[]; myBigInts = [10,40];This method is slower than the set-value method because the generated code must create two arrays: one for the variable and one for the literal.
myStringsInit string[] {"Hello", "Goodbye"}; myBigIntsInit bigint[] = [10, 40];
myDecimals decimal(10,2)[3] {55.43, 22.12, 4.34, CurrencySymbol = "$"};If you are using the array literal method to specify starting values, you can set properties with the set-value block as usual:
myBools boolean[3]{MaxSize = 5} = [true, false, true];
fiveInts int[5]; SysLib.writeStderr(fiveInts[1]); //Writes "0"When you create an array, specify a starting length for the array so that EGL can initialize it. You can add or remove elements later with array functions such as appendElement and removeElement.
nullArray int[]; nullArray[2] = 5; //NullValueException! nullArray.appendElement(5); //NullValueException! nullArray {1,2,3}; //NullValueException!Instead, you must begin by initializing the array with an array literal:
nullArray2 int[]; nullArray2 = [1,2,3]; nullArray2.appendElement(4);
emptyArray int[]{}; emptyArray.appendElement(5);In the previous example, the set-value block is empty. You cannot use a set-value block to assign more elements to an array than currently exist in the array. This array has zero elements, so you must use a set-value block with zero values.
smallIntArray int[2]; smallIntArray = [1,2,3,4,5];
smallStrArray string[2]; smallStrArray {"ab", "cd", "ef", "gh"}; //IndexOutOfBoundsException! Array has only 2 elements!
For more details about arrays, see "Arrays" in the Reference section.