Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

ds_grid_repr

By Daniel · December 29, 2008

Returns a string representation of the given grid

// ds_grid_repr(id)
// Returns a string representation of the given grid

var xx, yy, maxlen, s, row;

for (xx = 0; xx < ds_grid_width(argument0); xx += 1) {
  // Determine size of column
  maxlen = 0;
  for (yy = 0; yy < ds_grid_height(argument0); yy += 1)
    maxlen = max(maxlen, string_length(string(ds_grid_get(argument0, xx, yy))));
  
  for (yy = 0; yy < ds_grid_height(argument0); yy += 1) {
    s = string(ds_grid_get(argument0, xx, yy));
    s += string_repeat(' ', maxlen - string_length(s)); // pad
    if (xx == 0)
      row[yy] = s;
    else
      row[yy] += ' ' + s;
  }
}

s = '';
for (yy = 0; yy < ds_grid_height(argument0); yy += 1) {
  if (s != '')
    s += '#';
  s += row[yy];
}

return s;

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement