Legacy GM room_tile_add index in creation code

O

oziphantom

Guest
I'm adding/setting tiles in the 'creation code' for a room like so
GML:
var iy,ix,tileNum,tx,ty,px,py;

for (iy=0; iy < gMapHeightTiles ; iy++)
{
    for(ix=0; ix < gMapWidthTiles ; ix++)
    {
        tileNum = file_bin_read_byte(tileMapFile);
        px = ix * gMapTilePixelWidth;
        py = iy * gMapTilePixelHeight;
        tx = (tileNum % gBackTilesTileXCount) * gMapTilePixelWidth;
        ty = floor(tileNum / gBackTilesTileXCount) * gMapTilePixelHeight;
        show_debug_message("tileNum = "+string(tileNum)+" px = "+string(px)+" py = "+string(py)+" tx = "+string(tx)+" ty = "+string(ty));
        room_tile_add(room0,backTiles, tx, ty, gMapTilePixelWidth, gMapTilePixelHeight, px, py, 1);
    }
}
But nothing shows up, I just get a grey game window. If I go into the debugger, get the debugger to play ball, then "Restart" in the debugger it works. Which makes me think that room0 is correct, its just not assigned at the time of the creation script is called.
I've tried self, but that seems to be null also ( although the debugger calls everything <unknown> so don't really know ). I've tried 0 as a number as that is what I would expect an 'index' to be, same result. I've tried the name 'level1' that gets me an error telling me that no variable with that name exists. So it knows what room0 is at least.
The help file has
Code:
global.rm = room_add();
 room_assign(rm_Base, global.rm);
 room_tile_add(global.rm, tl_grass, 0, 0, 256, 32, 0, 400, 10000);
which doesn't help very much as I'm not making one in code. But i did try global.rm which is not defined and it crashes.

goolging for this function or, room creation script has yielded me nothing.

so what do I put as the index for room_tile_add in the create script?
 

rytan451

Member
I see your problem.

Here's the thing: a room (the resource you're modifying with room_tile_add) is basically a blueprint. It contains data about how to set up the running game. When you're adding tiles to the room, you're adding tiles to the blueprint, not to the running game.

This means, when you start the game, this happens:

The game looks at the blueprint (room0) and sets up the playing area.

The room creation code runs, adding tiles to the blueprint.

When you use the restart button in the debugger, the game starts at the first room. It looks at the modified blueprint (restarting the game doesn't undo modifications to assets). Then it sets up the playing area according to the blueprints, which now include the tiles.

Instead of room_tile_add, you should probably be using tile_add, which documentation you can find here: http://docs.yoyogames.com/source/da...ts/backgrounds/background tiles/tile_add.html
 
Top