EQWatcher Evolution > Scripting > dynarray.eas


dynarray.eas is one method of using dynamic arrays.  The reason they are called dynamic is they're not necessarily a particular size, they are resized depending on how they are used.

If you are new to programming, you might need a quick explanation of just what an array is.  Arrays are lists of information, indexed by a number.  These lists can store anything at all, such as player names or levels, mob names, etc.

How this implementation works is similar to "token strings".  A string variable is used to store the entire array.  Each element of the array is separated by semi-colons.  Using the positions of these semi-colons, the string is manipulated to retrieve or add the data of each element.  The first element of the array (element 0) stores the number of elements currently in the array (this is updated each time an element is added or removed).  This is mainly for quicker range checking to make sure you aren't trying to get or set an invalid element number.  The unfortunate part of this implementation is that the more information stored, the slower it gets (although it must get very very large to show slowness).

To use dynarray.eas in your script, simply #include it, by doing "#include "dynarray.eas"".

The functions of dynarray include: DAResetArray, DAAddElement, DAGetElement, DAInsertElement, DASetElement, DARemoveElement, DATotalElements.  Other functions are available, look at dynarray.eas for descriptions.


DAResetArray([Array])

Array must be the string being used as the array.  It is quicker to just set the string equal to "0;", but for the sake of transparency and not requiring the user to know how this works... this function is included.  The array is allowed to be an empty string, in which case it is automatically reset to "0;".


DAAddElement([Array],[Data])

Array must be the string being used as the array.  If the array is an empty string, it is automatically reset to a valid array.

Data is the string data you wish to add to the array.  This data becomes the final element in the array.


DAGetElement([Array],[Index],[Out])

Array must be the string being used as the array.

Index must be the element number you wish to retrieve.  Actual elements start at index 1 (index 0 stores the number of elements).

Out must be the string being used to retrieve the element data.


DAInsertElement([Array],[Data],[Number])

Array must be the string being used as the array.  If the array is an empty string, it is automatically reset to a valid array.

Data is the string data you wish to add to the array.  This data becomes the final element in the array.

Number is the element number this new data should become (the array is expected to be at least this size)


DASetElement([Array],[Index],[Data])

Array must be the string being used as the array.

Index must be the element number you wish to modify.  Actual elements start at index 1 (index 0 stores the number of elements).

Data must be the data to replace the current data of the specified element.


DARemoveElement([Array],[Index])

Array must be the string being used as the array.  If the array is an empty string, it is automatically reset to a valid array.

Index must be the element number you wish to remove.  Actual elements start at index 1 (index 0 stores the number of elements).


DATotalElements([Array])

Array must be the string being used as the array.  If the array is an empty string, it is automatically reset to a valid array.

This function returns the total number of elements in the array.