GMS 2 (SOLVED) grid problem

does anybody know why my grid look like this?
the red numbers shouldn't be like that



it should be setting the collision data depending on the quick mask.
but it seems to get messed up.

Code:
/// @desc load_solids()
/// @arg level

var level = argument[0];

var tile_len = level.length;
var ids      = layer_get_all();
var ids_len  = array_length_1d(ids);


//get first mask tileset
for (var l=0; l<ids_len; l++)
{
    var _id = layer_tilemap_get_id(ids[l]);
    show_debug_message("LAYER TILEMAP ID: "+string(_id))
    if (tilemap_get_tileset(_id) == ts_quick_mask) break;
}

//Loop though all tiles and set the collision grid data
for (var i=0; i<tile_len; i++)
{
    show_debug_message("LEVEL IS NULL: "+string(!instance_exists(level)));
    var _x    = i % tilemap_get_width(_id);
    var _y    = i / tilemap_get_width(_id);
    var _tile = tilemap_get(_id, _x, _y);
   
    switch (_tile)
    {
        case TM_MIDDLE:
            level.grid[# (_x*2)+0, (_y*2)+0] = 1;
            level.grid[# (_x*2)+1, (_y*2)+0] = 1;
            level.grid[# (_x*2)+0, (_y*2)+1] = 1;
            level.grid[# (_x*2)+1, (_y*2)+1] = 1;
            break;
        case TM_TOP:
            level.grid[# (_x*2)+0, (_y*2)+0] = 1;
            level.grid[# (_x*2)+1, (_y*2)+0] = 1;
            level.grid[# (_x*2)+0, (_y*2)+1] = 0;
            level.grid[# (_x*2)+1, (_y*2)+1] = 0;
            break;
        case TM_BOTTOM:
            level.grid[# (_x*2)+0, (_y*2)+0] = 0;
            level.grid[# (_x*2)+1, (_y*2)+0] = 0;
            level.grid[# (_x*2)+0, (_y*2)+1] = 1;
            level.grid[# (_x*2)+1, (_y*2)+1] = 1;
            break;
        case TM_LEFT:
            level.grid[# (_x*2)+0, (_y*2)+0] = 1;
            level.grid[# (_x*2)+1, (_y*2)+0] = 0;
            level.grid[# (_x*2)+0, (_y*2)+1] = 1;
            level.grid[# (_x*2)+1, (_y*2)+1] = 0;
            break;
        case TM_RIGHT:
            level.grid[# (_x*2)+0, (_y*2)+0] = 0;
            level.grid[# (_x*2)+1, (_y*2)+0] = 1;
            level.grid[# (_x*2)+0, (_y*2)+1] = 0;
            level.grid[# (_x*2)+1, (_y*2)+1] = 1;
            break;
        case TM_WATER:
            level.grid[# (_x*2)+0, (_y*2)+0] = 2;
            level.grid[# (_x*2)+1, (_y*2)+0] = 2;
            level.grid[# (_x*2)+0, (_y*2)+1] = 2;
            level.grid[# (_x*2)+1, (_y*2)+1] = 2;
            break;
        case TM_MUD:
            level.grid[# (_x*2)+0, (_y*2)+0] = 3;
            level.grid[# (_x*2)+1, (_y*2)+0] = 3;
            level.grid[# (_x*2)+0, (_y*2)+1] = 3;
            level.grid[# (_x*2)+1, (_y*2)+1] = 3;
            break;
    }
}
 
Top