Arrays
Data Types · Game object collections and level data.
Arrays
What it is
Arrays are ordered, indexed collections created with []. They support a huge set of methods: .push(), .pop(), .map(), .filter(), .forEach(), .find(), and many more. Arrays can hold values of any type, including other arrays and objects.
Why it matters
Arrays group entities so you can iterate over them. The entire level definition is fundamentally one array of game-object configs. Spline barriers are arrays of points. Dialogue button sets are arrays of options. Without arrays, every entity would need its own variable name.
How GateGame implements it
The this.classes array holds every instantiable entity in the level. Each spline segment is built from an array of [relX, relY] coordinate pairs. The Exit Warden’s dialogue options are an array of button config objects passed to addButtons(). The engine iterates these arrays each frame.
Code Example
// Array of coordinate pairs defining the maze path
const seg1 = spline('seg1', [
[0.03, 0.945],
[0.09, 0.940],
[0.20, 0.920],
[0.28, 0.895],
]);
// Array of game objects to instantiate
this.classes = [
{ class: Player, data: sprite_data_octopus },
{ class: Npc, data: sprite_data_warden },
];
Key Takeaway
Arrays are how you go from ‘one of this thing’ to ‘a collection of these things’ without inventing 50 variable names.