array_create_ext

This function creates an array of the given size. For each element in the new array, it calls the given callback function, and applies the return value to that element.

Using this function you can initialise the array with values that change depending on the array index.

Callback functionCallback function

The callback function supplied in the second argument should take 1 argument, which is the index of the current array element. It can return any type of value, which is stored in the array at that index.

Syntax:

function(index);

ArgumentTypeDescription
indexRealThe current array index

 

Syntax:

array_create_ext(size, function);

ArgumentTypeDescription
sizeRealThe size of the array
functionFunctionThe callback function used to initialise each entry

Returns:

Array

 

Example:

var _f = function(_index)
{
    return _index + 1;
}
array = array_create_ext(100, _f);
show_debug_message(array);

The above code first creates a temporary function _f that takes in an index as an argument, and returns that index with 1 added to it.

It then uses array_create_ext with the _f function which creates an array filled with the integer numbers from 1 to 100.