Getters β
This section covers two ways to retrieve created element IDs from Payload.
- Individual ID
.Get<ElementType>
getters.- Instances, Sprites, Particle Systems and Sequences use their room IDs.
- Tilemaps and Backgrounds use the name of the layer they're on.
- Type-based
.Get<ElementType>s()
getters that return an array of element IDs, using layer names for lookup.
NOTE
All code examples on this page assume you have an existing instance of Payload retrieved from RoomLoader.Load() and stored in a payload
variable.
.GetLayer()
β
Returns the created Layer ID matching the given name, or Undefined if not found.
Parameter | Type | Description |
---|---|---|
name | String | The layer name to search for |
// Gets the created "Clouds" layer ID and randomizes its horizontal speed:
var _cloudsLayer = payload.GetLayer("Clouds");
if (_cloudsLayer != undefined) {
layer_hspeed(_cloudsLayer, random_range(5, 8));
}
.GetLayers()
β
Returns an array of created Layers.
// Gets an array of created Layers and randomly toggles their visibility:
array_foreach(payload.GetLayers(), function(_layer) {
layer_set_visible(_layer, choose(true, false));
});
.GetInstance()
β
Returns the created Instance ID from the given room ID, or Noone if not found.
Parameter | Type | Description |
---|---|---|
roomId | Constant | The Instance room ID to search for |
// Grabs the created Instance ID from the InstWaypoint room ID and assigns it
// to objPlayer's waypointID:
objPlayer.waypointID = payload.GetInstance(InstWaypoint);
.GetInstances()
β
payload.GetInstances()
β Array of Id.Instance
Returns an array of created Instances.
// Gets an array of created Instances and targets a random one:
var _instances = payload.GetInstances();
var _randomInstance = script_execute_ext(choose, _instances);
.GetTilemap()
β
payload.GetTilemap(layerName)
β Id.Tilemap or Undefined
Returns the created Tilemap ID from the given layer name, or Undefined if not found.
Parameter | Type | Description |
---|---|---|
layerName | String | The Tile layer name to search for |
// Gets the created Tilemap ID from the "TilesCollision" layer
// to use for collision:
var _collisionTilemap = payload.GetTilemap("TilesCollision");
if (_collisionTilemap != undefined) {
array_push(global.collisionTilemaps, _collisionTilemap);
}
.GetTilemaps()
β
payload.GetTilemaps()
β Array of Id.Tilemap
Returns an array of created Tilemaps.
// Gets an array of created Tilemaps and targets a random one:
var _tilemaps = payload.GetTilemaps();
var _randomTilemap = script_execute_ext(choose, _tilemaps);
.GetSprite()
β
payload.GetSprite(roomId)
β Asset.GMSprite or Undefined
Returns the created Sprite ID matching the room ID, or Undefined if not found.
Parameter | Type | Description |
---|---|---|
roomId | String | The Sprite room ID to search for |
// Gets the created Sprite ID using its "SpriteStar" room ID, and if found,
// rotates it randomly:
var _sprite = payload.GetSprite("SpriteStar");
if (_sprite != undefined) {
layer_sprite_angle(_sprite, irandom(360));
}
.GetSprites()
β
payload.GetSprites()
β Array of Asset.GMSprite
Returns an array of created Sprites.
// Gets an array of created Sprites and blends them red:
array_foreach(payload.GetSprites(), function(_sprite) {
layer_sprite_blend(_sprite, c_red);
});
.GetSequence()
β
payload.GetSequence(roomId)
β Asset.GMSequence or Undefined
Returns the created Sequence ID matching the given room ID, or Undefined if not found.
Parameter | Type | Description |
---|---|---|
roomId | String | The Sequence room ID to search for |
// Gets the created Sequence ID using its "SequenceWindow" room ID, and if found,
// randomizes its playhead position:
var _sequence = payload.GetSequence("SequenceWindow");
if (_sequence != undefined) {
var _length = layer_sequence_get_length(_sequence);
layer_sequence_headpos(_sequence, random(_length));
}
.GetSequences()
β
payload.GetSequences()
β Array of Asset.GMSequence
Returns an array of created Sequences.
// Gets an array of created Sequences and randomizes their speed scales:
array_foreach(payload.GetSequences(), function(_sequence) {
layer_sequence_speedscale(_sequence, random(0.75, 1.25));
});
.GetBackground()
β
payload.GetBackground(layerName)
β Id.Background or Undefined
Returns the created Background ID matching the given layer name, or Undefined if not found.
Parameter | Type | Description |
---|---|---|
layerName | String | The Background layer name to search for |
// Gets the created Background ID from the "BackgroundClouds" layer and if found,
// blends it orange:
var _bg = payload.GetBackground("BackgroundClouds");
if (_bg != undefined) {
layer_background_blend(_bg, c_orange);
}
.GetBackgrounds()
β
payload.GetBackgrounds()
β Array of Id.Background
// Gets an array of created Backgrounds and randomizes their image indices:
array_foreach(payload.GetBackgrounds(), function(_bg) {
var _frames = sprite_get_number(layer_background_get_sprite(_bg));
layer_background_index(_bg, irandom(_frames - 1));
});