• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML ds_grid conventions

J

jb skaggs

Guest
when is it preferrable and why to use these items that seem to be the same thing:

my_grid[#1,1]=string;
ds_grid_add(my_grid,x,y,string);
ds_grid_set(my_grid,x,y,string);

same thing with reading

string=my_grid[#1,1];
string=ds_grid_get(my_grid,x,y);


thanks
 
H

Homunculus

Guest
First of all, ds_grid_add and ds_grid_set are totally different. ds_grid_add SUMS the value you pass with the existing value in the grid cell.

Other than that, you are right that the other are interchangeable. It has to do mainly with backwards compatibility, before accessors were introduced (accessors being my_grid[#1,1] this format, for ds_grid and the other ds_* functions) the only way to getand set data was by calling the _set and _get functions.

Using accessors is in my opinion easier and less verbose, and that's probably why they were introduced.
 

NazGhuL

NazTaiL
Same as @Catan. When using it multiple time, it's less 'overwhelming'. Takes less place on the screen.

ds_grid_set(grid, x, y, value];
ds_grid_set(grid, x, y, value];
ds_grid_set(grid, x, y, value];
ds_grid_set(grid, x, y, value];
ds_grid_set(grid, x, y, value];
ds_grid_set(grid, x, y, value];
ds_grid_set(grid, x, y, value];
ds_grid_set(grid, x, y, value];
ds_grid_set(grid, x, y, value];
ds_grid_set(grid, x, y, value];

vs

grid[# x, y] = value;
grid[# x, y] = value;
grid[# x, y] = value;
grid[# x, y] = value;
grid[# x, y] = value;
grid[# x, y] = value;
grid[# x, y] = value;
grid[# x, y] = value;
grid[# x, y] = value;
grid[# x, y] = value;
 
J

jb skaggs

Guest
First of all, ds_grid_add and ds_grid_set are totally different. ds_grid_add SUMS the value you pass with the existing value in the grid cell.

Other than that, you are right that the other are interchangeable. It has to do mainly with backwards compatibility, before accessors were introduced (accessors being my_grid[#1,1] this format, for ds_grid and the other ds_* functions) the only way to getand set data was by calling the _set and _get functions.

Using accessors is in my opinion easier and less verbose, and that's probably why they were introduced.
Could you show an example of the ds_grid_add ?
 

NazGhuL

NazTaiL
Code:
var grid = ds_grid_create(100, 100);
ds_grid_clear(grid, 55);

var aaa = grid[# 10,10];
show_message(aaa); //Will show 55

ds_grid_add(grid, 10, 10, 22);

show_message(aaa); //Will show 77

ds_grid_add(grid, 10, 10, -70);

show_message(aaa); //Will show 7
 
For the record, all the accessors are converted to their appropriate get/set functions before being compiled. the accessor way of doing things is just "syntactic sugar" as the saying goes.
 
Top