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)
/// 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);
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.Biased notes:
ds_grids are bad and you should consider arrays.
Could you elaborate?
ok, first ds_grid aren't bad I take it back but it is definetly worse at storing raw data.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.
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.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?
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.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?