GameMaker Bitwise operations and Ds_Grids

S

Snayff

Guest
Evening all,

I am converting a 2d array to a ds_grid but I am not sure how to convert the bitwise operations. Do we have to do something specific to use bitwise operations with ds_grid?


I have gone from
Code:
 oControllerTile.tileArray[_arrayHeight, _arrayLength] |= ISBLOCKINGMOVEMENT | ISBLOCKINGSIGHT;
to
Code:
ds_grid_set_region(oControllerTile.tileArray, 0, 0, ds_grid_width(oControllerTile.tileArray), ds_grid_height(oControllerTile.tileArray), ISBLOCKINGMOVEMENT | ISBLOCKINGSIGHT);
The value shown in the grid is 3, as expected.

However, when I not the bits to set them to 0 the value is -4.
Code:
ds_grid_set_region(oControllerTile.tileArray, _startingTileX, _startingTileY, _startingTileX + _widthOfRoom, _startingTileY + _heightOfRoom, (~ISBLOCKINGMOVEMENT) & (~ISBLOCKINGSIGHT) );

Any ideas?
Snayff
 

FrostyCat

Redemption Seeker
Your new code isn't doing bitwise arithmetic on the individual entries, it is simply setting entries in the grid directly to the value of a mask. Your question is as silly as asking why grid entries aren't decreased by 5 when you put -5 as the last argument to ds_grid_set_region().

Since you are NOT mass-assigning the same value to everything, you need to use a loop:
Code:
var ta = oControllerTile.tileArray,
    width = ds_grid_width(ta),
    height = ds_grid_height(ta);
for (var xx = width-1; xx >= 0; xx--) {
  for (var yy = height-1; yy >= 0; yy--) {
    ta[# xx, yy] &= ~(ISBLOCKINGMOVEMENT | ISBLOCKINGSIGHT);
  }
}
Also, you should check the data type on oControllerTile.tileArray. It is either a 2D array or it is a grid ID, not both. You cannot use grid operations on a 2D array or vice versa.
 
S

Snayff

Guest
@FrostyCat Thank you for coming back to me, and for the information.

That being said, I still don't know what benefit you think there is in adding scathing comments to an otherwise helpful reply. It certainly doesn't help me learn, nor does it engender a positive environment.
 
Top