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 methods. 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.
Parameter | Type | Description |
---|---|---|
room | Asset.GMRoom | The room to initialize data for |
... | Asset.GMRoom | Additional rooms. Accepts any number of arguments |
// 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.
Parameter | Type | Description |
---|---|---|
rooms | Array of Asset.GMRoom | The array of rooms to initialize data for |
// 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.
Parameter | Type | Description |
---|---|---|
prefix | String | The prefix used to filter room names |
// 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
Parameter | Type | Description |
---|---|---|
tag | String | The tag to parse rooms from |
// 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.
Parameter | Type | Description |
---|---|---|
blacklist | Array of Asset.GMRoom | The rooms to not initialize data for [Default: empty] |
// Initializes data for all rooms in the project BUT rmInit:
var _blacklist = [rmInit];
RoomLoader.DataInitAll(_blacklist);
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.
Parameter | Type | Description |
---|---|---|
room | Asset.GMRoom | The room to remove data for |
... | Asset.GMRoom | Additional rooms. Accepts any number of arguments |
// 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.
Parameter | Type | Description |
---|---|---|
rooms | Array of Asset.GMRoom | The array of rooms to remove data for |
// 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.
Parameter | Type | Description |
---|---|---|
prefix | String | The prefix used to filter room names |
// 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.
Parameter | Type | Description |
---|---|---|
tag | String | The tag to parse rooms from |
// 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.
Parameter | Type | Description |
---|---|---|
blacklist | Array of Asset.GMRoom | The rooms to not remove data for [Default: empty] |
// 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
).
Parameter | Type | Description |
---|---|---|
room | Asset.GMRoom | The room to check |
if (RoomLoader.DataIsInitialized(rmLevelTower)) {
// Yay, the data for rmLevelTower is initialized!
}
.DataGetWidth()
β
RoomLoader.DataGetWidth(room)
β Real
Returns the width of the given room.
Parameter | Type | Description |
---|---|---|
room | Asset.GMRoom | The room to get the width of |
// Gets the width of rmLevelDungeon:
var _width = RoomLoader.DataGetWidth(rmLevelDungeon);
.DataGetHeight()
β
RoomLoader.DataGetHeight(room)
β Real
Returns the height of the given room.
Parameter | Type | Description |
---|---|---|
room | Asset.GMRoom | The room to get the height of |
// Gets the height of rmLevelDungeon:
var _height = RoomLoader.DataGetHeight(rmLevelDungeon);
.DataGetLayerNames()
β
Returns an array of layer names for 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.
Parameter | Type | Description |
---|---|---|
room | Asset.GMRoom | The room to get an array of layer names for |
// 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()
β
Returns an array of instance data structs for the given room. Format listed below.
IMPORTANT
This method fetches the original 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().
Parameter | Type | Description |
---|---|---|
room | Asset.GMRoom | The room to get an array of instance data for |
// Fetches instance data for 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;
});
Struct Format β
Property | Type |
---|---|
ββ x | Real |
ββ y | Real |
ββ id | Id.Instance |
ββ object | Asset.GMObject |
ββ sprite | Asset.GMSprite |
ββ creationCode | Id.Function |
ββ preCreate | Struct |
Β Β Β Β ββ image_xscale | Real |
Β Β Β Β ββ image_yscale | Real |
Β Β Β Β ββ image_angle | Real |
Β Β Β Β ββ image_speed | Real |
Β Β Β Β ββ image_index | Real |
Β Β Β Β ββ image_alpha | Real |
Β Β Β Β ββ image_blend | Real |