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.
  • Removal - optional, for cleaning up data that's no longer needed.
  • Status & Getters - situational, for checking or retrieving room data.

Initialization

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

IMPORTANT

Loading is only possible for rooms with initialized data. Ensure that data initialization is completed before using Loading or Screenshotting functions. Attempting to use a room whose data hasn't been initialized will cause a crash.

TIP

While GMRoomLoader is optimized to handle data efficiently, this section is the most resource-intensive because it relies on room_get_info() to fetch and process room data.

For best results, call these methods at the very start of your game. If your project involves large amounts of data or requires loading/unloading during gameplay, call them between levels, hidden behind a transition or loading screen.


.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 to filter rooms with
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 to filter rooms with
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:
RoomLoader.DataRemoveAll([rmHub]);

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);

.DataGetInstances()

RoomLoader.DataGetInstances(room)Array of Struct

Returns an array of instance data structs for the given room. Format listed below.

ParameterTypeDescription
roomAsset.GMRoomThe room to get an array of instance data for
js
// Fetches instance data for rmExample:
var _instancesData = RoomLoader.DataGetInstances(rmExample); 

// Maps the data array to an array of instance IDs using a custom function
// for creating instances:
instances = array_map(_instancesData, function(_instanceData) {
    var _instanceId = ...; // Use _instanceData for custom instance creation.
    // More custom logic...
    return _instanceId;
});

Struct Format

PropertyType
├─ xReal
├─ yReal
├─ idId.Instance
├─ objectAsset.GMObject
├─ spriteAsset.GMSprite
├─ creationCodeId.Function
└─ preCreateStruct
    ├─ image_xscaleReal
    ├─ image_yscaleReal
    ├─ image_angleReal
    ├─ image_speedReal
    ├─ image_indexReal
    ├─ image_alphaReal
    └─ image_blendReal