• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

GML Need help with ds grids.

S

SyntheticStorm9

Guest
I am trying to make a simple variable storing grid but I cannot get it to work, if someone could post simple instructions for making a simple grid that would be really helpful,(creation,loading vars,submitting vars)
 

Simon Gust

Member
sure thing
Code:
/// create 
wdt = 64;
hgt = 64;
grid_name = ds_grid_create(wdt, hgt);

/// write
var xx = irandom(64);
var yy = irandom(64);
var val = random(10000);
ds_grid_set(grid_name, xx, yy, val);
// there will be a value between 0 and 10000 somewhere in this grid

/// read
var val = ds_grid_get(grid_name, xx, yy);
Visually literally excel





Biased notes:
ds_grids are bad and you should consider arrays.
 

toxigames

Member
Biased notes:
ds_grids are bad and you should consider arrays.
I do not agree that ds_grids are bad. On the contrary imo ds_grids are fast and very useful and convenient for solving lots of tasks. Remember to destroy the ds_grid with ds_grid_destroy(index) when you're done with it, or risk memory leaks.
 

Gamebot

Member
If all you want to do is store information you can simply use a 2d array. Its better on the system and you don't have to worry about destroying it when your done. I use these for both menus and inventory.

Though, in certain cases I use grids such as my playfair decoder/encoder simply because its easier to use the built in functions for getting x1, x2, y1, y2. I suppose someone else will post that im lazy with the previous. It just depends on what your planning to do with it.
 

Simon Gust

Member
Could you elaborate?
I do not agree that ds_grids are bad. On the contrary imo ds_grids are fast and very useful and convenient for solving lots of tasks. Remember to destroy the ds_grid with ds_grid_destroy(index) when you're done with it, or risk memory leaks.
ok, first ds_grid aren't bad I take it back but it is definetly worse at storing raw data.
The singlemost reason why I hate ds_grids is that when reading out of bounds, you get messages on your console without notice. If you play on fullscreen you have no way to see those while playing the game and when you abort it you'll be suprised to wait at least 10 minutes for the messages to clear. So if you're new to grids and try to figure them out you just get punished with timeouts. But if you used arrays, which are also faster, they would never do that, they just tell you in the face what's wrong.

In the end it depends on what you use.
arrays for raw data or LUTs
grids for dynamic visual data storing

Honestly though, who ever uses the extra functions in ds_grids?
 

toxigames

Member
ok, first ds_grid aren't bad I take it back but it is definetly worse at storing raw data.
The singlemost reason why I hate ds_grids is that when reading out of bounds, you get messages on your console without notice. If you play on fullscreen you have no way to see those while playing the game and when you abort it you'll be suprised to wait at least 10 minutes for the messages to clear. So if you're new to grids and try to figure them out you just get punished with timeouts. But if you used arrays, which are also faster, they would never do that, they just tell you in the face what's wrong.

In the end it depends on what you use.
arrays for raw data or LUTs
grids for dynamic visual data storing

Honestly though, who ever uses the extra functions in ds_grids?
Sure, ds_grids is not always the best choice I won't disagree with that. I have never had that out of bounds error happen, but I just tested it and you're right about writing to the grid the out of bounds error just prints to the console. One may or may not spot something wrong in game, depending on the particular effect the out of bounds error creates. I wonder why it doesn't actually throws and error? I wouldn't want my game continue to play (possibly with subtle bugs) with a near silent out of bounds error like that. Guess I learned something today ;) but even so this doesn't take away from all the convenience and flexibility ds_grids offer, but it is something to take extra care for I can see that. I couldn't provoke Gamemaker into hanging for 10 minutes though, even when going extreme out of bounds.

What are the extra functions of ds_grids? I use a lot of the ds_grid functions, far from all of them though, guess it depends on what you want to do?
 

Simon Gust

Member
What are the extra functions of ds_grids? I use a lot of the ds_grid functions, far from all of them though, guess it depends on what you want to do?
Things like getting the sum or the max value of a region of grid positions. I don't know what they're useful for but they're fast.
 
Well I use the min value of a region in my tetris-style game. The base grid is 0, blocks add 1 to the grid section they land on and then once the min value of a row is 1, I know it has been 'completed'.
 
Top