Scripting and tools
The DataTables script functions
One set of functions reaches every scripting language. In Visual Script they are listed under DataTables. AngelScript reaches them through reflection. C# gets them from the generated engine bindings, and the exact C# signatures are in your project's generated PlasmaEngineBindings.g.cs.
A static table or table set is named by its asset GUID, as a string. A store table is named by the name it is declared with in the project settings, such as Inventory.
Static tables
| Function | Inputs | Returns | Notes |
|---|---|---|---|
HasRow | Table, Key | bool | |
GetCell | Table, Key, Column | variant | Invalid when the table, row or column does not exist. Text cells come back translated. |
GetRowCount | Table | int | |
GetRowKeyAt | Table, Index | string | Rows in document order. |
FindRows | Table, Query | variant (array of keys) | A text query such as Where(Rarity == Epic).OrderBy(DPS desc).Take(5). An empty query returns every key. |
PickWeighted | Table, Query, WeightColumn, Seed | string (key) | A weighted random pick among the query's rows. The same seed returns the same row. Empty when nothing can be picked. |
GetRefKey | Table, Key, Column | string | The key a Row column points at. |
GetRefTable | Table, Key, Column | string | The table a Row column points at, to use with GetCell. |
Table sets
| Function | Inputs | Returns | Notes |
|---|---|---|---|
SetLayerEnabled | TableSet, Layer, Enabled | none | Merges the set again when the state changes. |
IsLayerEnabled | TableSet, Layer | bool |
Data store
| Function | Inputs | Returns | Notes |
|---|---|---|---|
StoreHasRow | Table, Row | bool | |
StoreGetRowCount | Table | int | |
StoreGetRowKeyAt | Table, Index | string | |
StoreGet | Table, Row, Column | variant | |
StoreSet | Table, Row, Column, Value | bool | Adds the row when needed. |
StoreIncrement | Table, Row, Column, Delta | bool | Adds the row when needed. |
StoreAdd / StoreRemove | Table, Row | bool | |
StoreClear | Table | none | |
StoreBeginTransaction, StoreCommit, StoreRollback | none | none | See Transactions. |
To react to store changes in a script, add a Data Table Events component to the object and handle plMsgDataStoreChanged. See Reacting to changes.
Example: a loot roll in Visual Script
- Add DataTables · PickWeighted. Set Table to the loot table's GUID, Query to
Where(Tier <= 2), WeightColumn toWeight. - Feed Seed from the crate's own seed so that the same crate always drops the same item.
- Pass the returned key to DataTables · StoreIncrement with Table
Inventory, ColumnCount, Delta 1.
Live Data panel
Panels > Show Panels > Live Data shows the tables of the running engine process, for example during Play. It is the fastest way to check what the game actually sees, and to give a tester 999 gold.
- The title line shows whether an engine process is running, how many static and store tables it has, and the store generation. Without an engine process, the panel says so instead of showing old data.
- The list on the left groups the tables: Static for loaded data tables, Store: Profile, Store: Slot and Store: Session for store tables, each with its row count.
- Static tables are read-only here. Edit them in their table window and the change reaches the game by hot reload.
- Store tables are editable: double-click a cell to change it, and use Add row and Remove row. Changed rows are highlighted briefly. The panel refreshes when the table changes in the game.
- Large tables are shown in pages: the header says showing the first n of m rows.
- The Query box runs a text query against the selected table, using the same code the game uses. Click one of the example chips below it to start from an example.
- The log at the bottom lists incoming store events: type, table, row, column, old and new value.
Project settings
Project > Data Tables… has two pages.
| Page · setting | Default | Description |
|---|---|---|
| Data Store | no tables | The store table declarations, written to RuntimeConfigs/DataStore.ddl. See Data store & saving. |
| General · Generate code | off | Allows schemas marked Generate code for this schema to write C++ row headers and the schema manifest. See Generated C++ row headers. |
| General · Strict validation | off | Turns every range, length and pattern warning in the project into a transform error. |
The General page settings are stored in the project's Editor/DataTables.ddl.
Console commands
Available in the game's console. The console is a Lua interpreter, so commands are called like functions with string arguments.
| Command | Arguments | Description |
|---|---|---|
DataTables.Dump | table | Prints every row of a data table. |
DataTables.Query | table, query | Runs a text query and prints the rows. |
DataStore.Dump | table | Prints every row of a store table. |
DataStore.Set | table, row, column, value | Writes one store cell. The value text is parsed for the column's type. |
DataTables.Dump("{ 4ec80001-6d67-1bc1-0100-64a7b3b6e00d }")
DataTables.Query("{ 4ec80001-6d67-1bc1-0100-64a7b3b6e00d }", "Where(Damage > 30).OrderBy(Damage desc).Take(4)")
DataStore.Set("Wallet", "gold", "Amount", "999")
DataStore.Dump("Wallet")
CVars
| CVar | Default | Description |
|---|---|---|
DataTables.LogQueries | false | Logs every query with its matched and returned row counts and its time. |
DataStore.ValidateWrites | true in Development builds | Warns when a store write is outside the column's range. |