Skip to content

Data ​

This section covers room data management - GMRoomLoader's entry point and the beginning of its intended workflow. It's divided into three modules:

  • Initialization - essential for setting up room data before Loading, Screenshotting or using Data Getters. Happens automatically, but best performed on game start or behind loading screens (where applicable) for performance reasons.
  • Removal - optional, use for cleaning up loaded elements that are no longer needed, AKA "unloading" or "destroying" rooms.
  • Status & Getters - situational, for checking or retrieving room data.

Initialization ​

The following methods initialize room data to be used for Loading and Screenshotting.

❗ PERFORMANCE NOTE

Initialization is the most resource-intensive operation in the entire library. It parses room data from room_get_info() and optimizes it for fast Loading and Screenshotting.

ℹ️ For best performance, call these methods at the very start of your game.

ℹ️ If room data hasn't been initialized before calling Loading, Screenshotting or Data Getters, GMRoomLoader will initialize it automatically. While convenient for quick testing or handling small rooms, doing this noticeably slows down the aforementioned methods and should be avoided when dealing with bigger rooms.


.DataInit() ​

RoomLoader.DataInit(...rooms) ➜ Struct.RoomLoader

Initializes data for all given rooms.

ParameterTypeDescription
roomAsset.GMRoomThe room to initialize data for
...Asset.GMRoomAdditional rooms. Accepts any number of arguments
js
// Initializes data for rmLevelCastle:
RoomLoader.DataInit(rmLevelCastle); 

// Initializes data for rmLevelPlains, rmLevelForest and rmLevelCliffs:
RoomLoader.DataInit(rmLevelPlains, rmLevelForest, rmLevelCliffs); 

.DataInitArray() ​

RoomLoader.DataInitArray(rooms) ➜ Struct.RoomLoader

Initializes data for all rooms in the given array.

ParameterTypeDescription
roomsArray of Asset.GMRoomThe array of rooms to initialize data for
js
// Initializes data for all rooms inside the rooms array:
rooms = [rmLevelCabin, rmLevelAlley, rmLevelBeach];
RoomLoader.DataInitArray(rooms); 

.DataInitPrefix() ​

RoomLoader.DataInitPrefix(prefix) ➜ Array of Asset.GMRoom

Initializes data for all rooms starting with the given prefix. Returns an array of found rooms.

ParameterTypeDescription
prefixStringThe prefix used to filter room names
js
// Initializes data for all rooms starting with "rmLevel" and stores found room IDs in a variable:
rooms = RoomLoader.DataInitPrefix("rmLevel"); 

.DataInitTag() ​

RoomLoader.DataInitTag(tag) ➜ Array of Asset.GMRoom

ParameterTypeDescription
tagStringThe tag to parse rooms from
js
// Initializes data for all rooms with the "Dungeon" tag assigned and stores their IDs in a variable:
dungeonRooms = RoomLoader.DataInitTag("Dungeon"); 

.DataInitAll() ​

RoomLoader.DataInitAll(blacklist) ➜ Struct.RoomLoader

Initializes data for all rooms in the project, except the ones listed in the blacklist array.

ParameterTypeDescription
blacklistArray of Asset.GMRoomThe rooms to not initialize data for [Default: empty]
js
// Initializes data for all rooms in the project BUT rmInit:
RoomLoader.DataInitAll([rmInit]); 

Removal ​

Although initialized room data takes up little space, you may still want to remove it for rooms that are no longer needed. The following methods follow the Initialization structure and remove the corresponding data from RoomLoader's internal pool.


.DataRemove() ​

RoomLoader.DataRemove(...rooms) ➜ Struct.RoomLoader

Removes data for all given rooms.

ParameterTypeDescription
roomAsset.GMRoomThe room to remove data for
...Asset.GMRoomAdditional rooms. Accepts any number of arguments
js
// Removes data for rmLevelCastle:
RoomLoader.DataRemove(rmLevelCastle); 

// Removes data for rmLevelPlains, rmLevelForest and rmLevelCliffs:
RoomLoader.DataRemove(rmLevelPlains, rmLevelForest, rmLevelCliffs); 

.DataRemoveArray() ​

RoomLoader.DataRemoveArray(rooms) ➜ Struct.RoomLoader

Removes data for all rooms in the given array.

ParameterTypeDescription
roomsArray of Asset.GMRoomThe array of rooms to remove data for
js
// Removes data for all rooms inside the rooms array:
rooms = [rmLevelCabin, rmLevelAlley, rmLevelBeach];
RoomLoader.DataRemoveArray(rooms); 

.DataRemovePrefix() ​

RoomLoader.DataRemovePrefix(prefix) ➜ Struct.RoomLoader

Removes data for all rooms starting with the given prefix.

ParameterTypeDescription
prefixStringThe prefix used to filter room names
js
// Removes data for all rooms starting with "rmLevel":
RoomLoader.DataRemovePrefix("rmLevel"); 

.DataRemoveTag() ​

RoomLoader.DataRemoveTag(tag) ➜ Struct.RoomLoader

Removes data for all rooms with the given tag.

ParameterTypeDescription
tagStringThe tag to parse rooms from
js
// Removes data for all rooms with the "Dungeon" tag assigned:
RoomLoader.DataRemoveTag("Dungeon"); 

.DataRemoveAll() ​

RoomLoader.DataRemoveAll(blacklist) ➜ Struct.RoomLoader

Removes data for all rooms, except the ones listed in the blacklist array.

ParameterTypeDescription
blacklistArray of Asset.GMRoomThe rooms to not remove data for [Default: empty]
js
// Removes data for all rooms in the project BUT rmHub:
var _blacklist = [rmHub];
RoomLoader.DataRemoveAll(_blacklist); 

Status & Getters ​

.DataIsInitialized() ​

RoomLoader.DataIsInitialized(room) -> Bool

Checks whether the data for the given room is initialized (returns true) or not (returns false).

ParameterTypeDescription
roomAsset.GMRoomThe room to check
js
if (RoomLoader.DataIsInitialized(rmLevelTower)) { 
    // Yay, the data for rmLevelTower is initialized!
}

.DataGetWidth() ​

RoomLoader.DataGetWidth(room) ➜ Real

Returns the width of the given room.

ParameterTypeDescription
roomAsset.GMRoomThe room to get the width of
js
// Gets the width of rmLevelDungeon:
var _width = RoomLoader.DataGetWidth(rmLevelDungeon); 

.DataGetHeight() ​

RoomLoader.DataGetHeight(room) ➜ Real

Returns the height of the given room.

ParameterTypeDescription
roomAsset.GMRoomThe room to get the height of
js
// Gets the height of rmLevelDungeon:
var _height = RoomLoader.DataGetHeight(rmLevelDungeon); 

.DataGetLayerNames() ​

RoomLoader.DataGetLayerNames(room) ➜ Array of String

Returns an array of layer names from the given room, in the order defined in the room editor. Can be safely operated on with array functions since the internal data is not touched.

ParameterTypeDescription
roomAsset.GMRoomThe room to get an array of layer names from
js
// Fetches layers names from rmLevelGarden and whitelists 3 random layers before loading:
var _room = rmLevelGarden;
var _layerNames = RoomLoader.DataGetLayerNames(_room); 
array_shuffle_ext(_layerNames);
array_resize(_layerNames, 3);
array_foreach(_layerNames, function(_layerName) {
    RoomLoader.LayerWhitelistAdd(_layerName);
});
RoomLoader.Load(_room, x, y);
RoomLoader.LayerWhitelistReset();

.DataGetInstances() ​

RoomLoader.DataGetInstances(room, [object]) ➜ Array of Struct

Returns an array of instance data structs from the given room. See the format listed below.

You can also provide the optional [object] argument to return data only for instances of the given object.

IMPORTANT

This method fetches the internal data structs, which should NOT be changed externally. Doing so might affect future loading in undesirable ways. If you need to edit the returned structs, clone the array first using variable_clone().

ParameterTypeDescription
roomAsset.GMRoomThe room to get an array of instance data from
[object]Asset.GMObjectThe object to filter instances by. Only instances of the given object will be included
js
// Fetches instance data from rmExample:
var _instancesData = RoomLoader.DataGetInstances(rmExample); 

// Maps the data array to an array of instance IDs using a custom instance creation function:
instances = array_map(_instancesData, function(_instanceData) {
    var _instanceId = ...; // Use _instanceData for custom instance creation.
    // More custom logic...
    return _instanceId;
});
js
// Fetches objDoor instance data from rmExample:
var _doorsData = RoomLoader.DataGetInstances(rmExample, objDoor); 
// ...

.DataGetInstance() ​

RoomLoader.DataGetInstance(room, instanceId) ➜ Struct

Returns an instance data struct for the given room instance inside the given room. See the format listed below.

js
var _leftDoor = RoomLoader.DataGetInstance(rmExample, inst_2C16415); 
// ...

Struct Format ​

PropertyType
β”œβ”€ xReal
β”œβ”€ yReal
β”œβ”€ idId.Instance
β”œβ”€ objectAsset.GMObject
β”œβ”€ creationCodeId.Function
└─ preCreateStruct
Β Β Β Β β”œβ”€ sprite_indexAsset.GMSprite
Β Β Β Β β”œβ”€ image_indexReal
Β Β Β Β β”œβ”€ image_speedReal
Β Β Β Β β”œβ”€ image_xscaleReal
Β Β Β Β β”œβ”€ image_yscaleReal
Β Β Β Β β”œβ”€ image_angleReal
Β Β Β Β β”œβ”€ image_blend:Constant.GMColor:, Real
    └─ image_alphaReal

Any variables adjusted through the Variable Definitions tab are also included in the struct. Variables with untouched default values are ignored - room_get_info() doesn't provide any data for those.


.DataGetTilemap() ​

RoomLoader.DataGetTilemap(room, layerName) ➜ Struct

Returns a {tileset, width, height, tiles} data struct for the tilemap from the given layer in the given room.

The tiles array is laid out in x, y, tileData data sets for each tile: [x, y, tileData, x, y, tileData, ...], where x and y are tile coordinates in tilemap space and tileData is the tile data used in tilemap functions.

ℹ️ WHY THIS FORMAT?
  • Why not a 2d array? Tilemap loading is optimized by removing empty 0 tiles from internal data, and there's no need to track empty cells in the resulting array used for creating tilemaps.
  • Why not an array of structs? Having a single flat 1d array is both faster and more memory efficient compared to an array of structs.
ParameterTypeDescription
roomAsset.GMRoomThe room to get tilemap data from
layerNameStringThe Tile layer name to get tilemap data from
js
// Fetches tilemap data from rmExample's "Tiles" layer:
var _tilemapData = RoomLoader.DataGetTilemap(rmExample, "Tiles"); 

// Loops through the 'tiles' array:
var _tiles = _tilemapData.tiles;
var _i = 0; repeat (array_length(_tiles) / 3) {
    var _x = _tiles[_i];
    var _y = _tiles[_i + 1];
    var _tile = _tiles[_i + 2];
    // Does something really cool with each tile...
    _i += 3;
}