You are not logged in.
Pages: 1
This is great, I hadn't even thought of this before. It does make sense though. I'll work on both scripts and test them. I'll update each version accordingly along with the original post. Thanks
I created a quality of life 2D array creation script with debugging built in. It allows you to initialize a 2D array of any size with a value (optional).
Edit: Updated the functions with optimized array creation, and built in debugging. Along with a few other optimization tweaks. Thanks xot!
GMS 1.4
/// array_init_2d(size_x, size_y, debug, [value])
// Create a two dimensiona array, initialized with [value] (optional).
// size_x : The width of the array.
// size_y : The height of the array.
// debug : Output debug information in the compiler output? 'true' or 'false'
// [value] : Optional value for initialized array indices.
// Script Created By: JangersBrah
// Special Thanks To: xot(GMLscripts.com - Forum Admin)
// GMLscripts.com/license
var v, k, debug, value; // Declare local variables...
debug = argument[2]; // Is debug 'true' or 'false'?
value = 0; // Default value to 0...
for (v = argument[0] - 1; v >= 0; v -= 1;) // Reverse loop through x axis...
{
for (k = argument[1] - 1; k >= 0; k -= 1;) // Reverse loop through y axis...
{
if (argument_count > 3) // Was a value given?
{
value = argument[3]; // It was! Set value to [value]...
}
array[v, k] = value; // Set array index value...
if (debug == true) // Is debugging set to 'true'?
{
show_debug_message("[" + string(v) + ", " + string(k) + "] = " + string(value)); // It was! Output debug information in compiler output...
}
}
}
return array; // Return array...
GMS 2.1.5
/// @function array_init_2d(size_x, size_y, debug, [value])
/// @description Create a two dimensiona array, initialized with [value] (optional).
/// @param {real} size_x The Width of the array.
/// @param {real} size_y The Height of the array.
/// @param {bool} debug Output debug information in the compiler output? 'true' or 'false'
/// @param {undefined} [value] Optional value for initialized array indices.
// Script Created By: JangersBrah
// Special Thanks To: xot(GMLscripts.com - Forum Admin)
// GMLscripts.com/license
var v, k, debug, value; // Declare local variables...
debug = argument[2]; // Is debug 'true' or 'false'?
value = 0; // Default value to 0...
for (v = argument[0] - 1; v >= 0; v -= 1;) // Reverse loop through x axis...
{
for (k = argument[1] - 1; k >= 0; k -= 1;) // Reverse loop through y axis...
{
if (argument_count > 3) // Was a value given?
{
value = argument[3]; // It was! Set value to [value]...
}
array[v, k] = value; // Set array index value...
if (debug == true) // Is debugging set to 'true'?
{
show_debug_message("[" + string(v) + ", " + string(k) + "] = " + string(value)); // It was! Output debug information in compiler output...
}
}
}
return array; // Return array...
Pages: 1