Skip to content

Instantly share code, notes, and snippets.

@derme302
Created January 29, 2015 10:04
Show Gist options
  • Save derme302/f6f85b9445b80335f02f to your computer and use it in GitHub Desktop.
Save derme302/f6f85b9445b80335f02f to your computer and use it in GitHub Desktop.
Import a array into a ds_grid
///ds_grid_import_array(ds_grid, array)
var grid = argument[0];
var arr = argument[1];
// Calculate array Size
var height = array_height_2d(arr);
var width = 0;
for (var i = 0; i < height; i++) {
if (array_length_2d(arr, i) > width)
width = array_length_2d(arr, i);
}
// Resize ds_grid to the correct dimensions
ds_grid_resize(grid, width, height);
ds_grid_clear(grid, -1);
// Import array into ds_grid
for (var i = 0; i < height; i++) {
for (var j = 0; j < width; j++) {
ds_grid_set(grid, j, i, arr[i, j]);
trace("Grid " + string(i) + " , " + string(j) + ":" + string(ds_grid_get(grid, j, i)));
}
}
@derme302
Copy link
Author

Example Usage (With CSV Manager Installed):

/// Load, modify and save a .csv
my_csv = csv_load("demo"); // Load the demo csv into the "my_csv" array
global.my_ds_grid = ds_grid_create(1, 1); // Create a ds_grid
ds_grid_import_array(global.my_ds_grid, my_csv); // Import the array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment