Skip to main content

Data tables

A data table keeps the facts about your game in one place: what every item is, how strong every enemy is, which levels there are. It is a file in the Files tab, like Unity's ScriptableObjects, but edited as a spreadsheet.

Each column is a field every row has (a name, a price, a picture) and each row is one thing (a Sword, a Potion). Change a price in the table and everything that reads it changes, with no event or script edited.

A table holds what is fixed when the game is made. What changes while playing, such as how many Potions the player holds, belongs in variables or game.save, which can keep lists and objects.

Make a table​

  1. Files → + New → Data table, name it (for example Item). It opens in the table editor. The Tables chip in Files shows only tables.

  2. Columns: add one for each field. Give it a name (letters, digits and _; it is read as row.damage) and a type:

    TypeHolds
    Text, Number, True / falseWhat you type.
    ChoiceOne of the words you list (Weapon, Potion, Key), as a dropdown.
    ColorA colour.
    Image, Sound, PrefabA file from Files.
    Row of a tableA row of another table (or the same one): an item's upgrade, an enemy's loot.

    New rows start as sets what a new row holds in that column.

  3. + Row adds a row. Give it a Name, the word you look it up by (Sword); no two rows share a name. The ⋯ menu moves, duplicates and deletes a row.

You can rename, duplicate and delete a table from its card's menu, and drag it into folders like any file.

Read it in a script​

const items = game.table('Item');
const sword = items.get('Sword'); // the row, or null
sword.title; // 'Iron Sword'
sword.damage; // 7
sword.id; // 'Sword', the row's name

items.all(); // every row, in the table's order
items.where((r) => r.kind === 'Potion');
items.ids(); // ['Sword', 'Heal Potion', …]
items.has('Axe');
items.length; // how many rows

A row is read-only. A Row of a table column reads as that row's object, so sword.next.title goes on to the next item.

A script field can point at a row, and the Inspector shows a picker for it:

export let loot = field.data('Item'); // the row (or null)
export let shop = field.list(field.data('Item')); // an array of rows

In the code editor, game.table('Item').get('Sword'). suggests the table's columns.

Read it in events​

Expressions work anywhere an expression does:

ExpressionGives
table("Item", "Sword", "damage")One cell: the table, the row's name, the column.
tablecount("Item")How many rows.
tablerow("Item", i)The name of row i, counting from 0.

Put tablerow inside a Repeat or For loop and every row is yours:

  • Repeat tablecount("Item") times → Spawn …, using table("Item", tablerow("Item", loopIndex), "title").

A missing table, row or column is reported as a friendly error instead of failing silently.