Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

[Solved - GM oddity] Live Rooms - getting layer & tileset IDs inside the live room?

A topic by Game Soup LLC created Mar 29, 2020 Views: 444 Replies: 5
Viewing posts 1 to 3
(1 edit)

So I'm attempting to use a "live room." The non-live version of the room (which has 5 tilemap layers) works normally and each tileset layer has the correct tilemap ID (via layer_tilemap_get_id). But loading the live version of the same room, I can't seem to access the layers that hold those 5 tilesets. for example, the room I'm testing inherits its layers, and has a layer named "tsLayerMain" is a tileset layer with tileset resource "tileset_plain." And while the layer does still exist in the live room, it no longer has a tileset/tilemap associated with it (but the tiles that I placed in the editor still appear in the live version of the room). In the live room's create event, I stored a variable for the layer "tsLayerMain" as a global variable, and tested that it does exist with layer_exists(), but layer_tilemap_get_id returns -1

The reason I want this layer's tileset ID is because in this game, I place invisible collision objects overtop of tilesets, and I need to use get_tilemap_at_pixel() with the correct tileset_element_id, but I can't retrieve the tileset's ID with layer_tilemap_get_ID.

I assume this is related to tilesets  being added to the "live" room during runtime instead of through the IDE, but because it all works normally when I'm not using the live version of the room, I'm not exactly sure what I need to be changing. I don't think that the "live"/"non-live" instances section of the documentation apply here, but I created globals for the object_indices of the objects in the room just in case.

 Since all the tiles placed in the editor still appear, I know they're on a layer somewhere in the room, but I can't figure out how to access the layer that the tiles are actually on (if there even is a way to do so).

Developer

If you can email me a sample project where this happens, I'll take a look.

(1 edit)

I'm having the same issue, the tilemap's don't load or aren't accessible from the layers. Was this ever resolved?

Developer

As we have talked on Discord, you cannot layer_tilemap_get_id on dynamically created layers.

You will have to make a small script like

/// layer_tilemap_get_id_fixed(layer)
var els = layer_get_all_elements(argument0);
var n = array_length_1d(els);
for (var i = 0; i < n; i++) {
    var el = els[i];
    if (layer_get_element_type(el) == layerelementtype_tilemap) {
        return el;
    }
}
return -1;

Worked like a charm, most appreciated!

Great to hear that this worked for the other person too. Due to some poor planning, it would have been a headache to try and send you a project that demonstrated the issue (since the extension is integrated into a big project at the moment), and given that nobody else seemed to have the same problem, I would much sooner assume it was my own fault rather than a problem with Game Maker, so I sort of gave up on it. But once again, YellowAfterlife comes to the rescue and sets us all straight <3 Thanks so much for the explanation and script.