The "array_create_2d" Function

Syntax

array_create_2d(width, height, [value]);
ArgumentTypeDescription
widthrealSets the number of horizontal cells in the array
heightrealSets the number of vertical cells in the array
[value]real/stringOptional: Sets a value to assign to all new cells (default 0)

Description

Creates and returns a 2D array of the given with and height, optionally assigning a custom default value to each index.

Theoretically, this can be achieved in vanilla GML by declaring a 2D arrray with a single value assigned to the maximum desired index in either axis. However, many export modules do not recognize this form of declaration, resulting in crashes. By contrast, GML+ uses a safe method to initialize every cell in order to avoid errors.

Example

my_array = array_create_2d(10, 5);
my_array = array_create_2d(10, 5, -1);