Last active
June 1, 2023 01:29
-
-
Save tabularelf/ea7901007179d48ce2f61e6e2fe026da to your computer and use it in GitHub Desktop.
Recreating GameMaker's 2D arrays, now that they're deprecated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Made by TabularElf | |
/// @func array_2d_height | |
/// @param 2DArray | |
function array_2d_height(_array) { | |
return array_length(_array); | |
} | |
/// @func array_2d_length | |
/// @param 2DArray | |
/// @param [Height] | |
function array_2d_length(_array, _n = 0) { | |
// Used to determine _n as an optional argument | |
return array_length(_array[_n]); | |
} | |
/// @func array_2d_create | |
/// @param Height | |
/// @param Length | |
/// @param [Value] | |
function array_2d_create(_height, _length, _value = 0) { | |
var _array; | |
array[_height] = 0; | |
for(var _i = 0; _i < _height; ++_i) { | |
_array[_i] = array_create(_length, _value); | |
} | |
return _array; | |
} | |
/// @func array_2d_resize | |
/// @param 2DArray | |
/// @param Height | |
/// @param [Length] | |
function array_2d_resize(_array, _height, _length) { | |
// Resize height | |
array_resize(_array, _height); | |
// Resize Lengths | |
if (_length != undefined) { | |
for(var _i = 0; _i < _height; ++_i) { | |
if (!is_array(_array[@ _i])) { | |
_array[@ _i] = array_create(_length); | |
} else { | |
array_resize(_array[@ _i], _length); | |
} | |
} | |
} | |
} | |
/// @func array_2d_get | |
/// @param array2D | |
/// @param height | |
/// @param length | |
function array_2d_get(_array2D, _height, _length) { | |
return _array2D[_height][_length]; | |
} | |
/// @func array_2d_set | |
/// @param array2D | |
/// @param height | |
/// @param length | |
/// @param value | |
function array_2d_set(_array2D, _height, _length, _value) { | |
_array2D[@ _height][@ _length] = _value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment