The "array_fill_2d" Function

Syntax

array_fill_2d(id, [value]);
ArgumentTypeDescription
idarrayThe index of a previously-created array to modify
[value]real/stringOptional: Sets a value to assign to all new cells (default 0)

Description

Unlike ds_grid, 2D arrays have non-uniform columns, meaning each can have a different height. This is often problematic, and it would be preferable to have empty cells rather than no cells at all.

This script takes an existing 2D array and fills the vertical gaps, optionally assigning a custom default value to each index.

It is highly recommended to run this script before array_write or looping through 2D array contents if the height is not known to be uniform.

Example

array_fill_2d(my_array);
array_fill_2d(my_array, -1);