mod.data
Read and change game data from Luau. The same operations as data/<kind>.json files. Writes work only while your mod loads.
mod.data.add(kind, id, record)
Section titled “mod.data.add(kind, id, record)”server + client
Adds a record. The id must be new, and the kind must allow adding (see each kind’s page). Every required field must be there.
| Parameter | Type | |
|---|---|---|
kind |
string |
A data kind. |
id |
string |
The new record’s id. |
record |
table |
The full record. |
Raises
data is read-only once the game has started; register it while the mod loadskind must be textid must be text
mod.data.add("superweapons", "sunburst", { base = "sunlance", name = "Sunburst", short = "BURST", color = { 255, 140, 40 }, price = 500, cooldown = 200,})mod.data.patch(kind, id, fields)
Section titled “mod.data.patch(kind, id, fields)”server + client
Changes the listed fields of an existing record. Maps (w, build, req…) merge key by key; lists and colours are replaced. Set a field to mod.REMOVE to delete it.
| Parameter | Type | |
|---|---|---|
kind |
string |
A data kind. |
id |
string |
An existing record. |
fields |
table |
Only the fields to change. |
Raises
data is read-only once the game has started; register it while the mod loads
mod.data.patch("ships", "destroyer", { cost = 1500, speed = 45 })mod.data.replace(kind, id, record)
Section titled “mod.data.replace(kind, id, record)”server + client
Replaces a whole record. Only for kinds you can add to; use patch for the others.
| Parameter | Type | |
|---|---|---|
kind |
string |
A kind that allows adding. |
id |
string |
An existing record. |
record |
table |
The full new record. |
Raises
data is read-only once the game has started; register it while the mod loads
local r = mod.data.get("bots", "raider")local copy = {}for k, v in r do copy[k] = v endcopy.war = 5mod.data.replace("bots", "raider", copy)mod.data.remove(kind, id)
Section titled “mod.data.remove(kind, id)”server + client
Removes a record. Only upgrades and strings allow it.
| Parameter | Type | |
|---|---|---|
kind |
string |
upgrades or strings. |
id |
string |
An existing record. |
Raises
data is read-only once the game has started; register it while the mod loads
mod.data.remove("upgrades", "qol_bulk100")mod.data.get(kind, id)
Section titled “mod.data.get(kind, id)”server + client
A read-only copy of the record as it stands now: the base game plus every mod that loaded before you.
| Parameter | Type | |
|---|---|---|
kind |
string |
A data kind. |
id |
string |
A record id. |
Returns table? (frozen), or nil if there is no such record
local d = mod.data.get("ships", "destroyer")mod.log("destroyer costs", d.cost)mod.data.has(kind, id)
Section titled “mod.data.has(kind, id)”server + client
True if the record exists.
| Parameter | Type | |
|---|---|---|
kind |
string |
A data kind. |
id |
string |
A record id. |
Returns boolean
if mod.data.has("superweapons", "solarflare") then mod.log("Solar Flare is installed")endmod.data.list(kind)
Section titled “mod.data.list(kind)”server + client
The ids of a kind: the game’s order, then added ones.
| Parameter | Type | |
|---|---|---|
kind |
string |
A data kind. |
Returns { string }
for _, id in mod.data.list("ships") do mod.log(id)endmod.data.kinds()
Section titled “mod.data.kinds()”server + client
Every kind name, sorted.
Returns { string }
mod.log(table.concat(mod.data.kinds(), ", "))mod.REMOVE
Section titled “mod.REMOVE”server + client marker
The delete marker for patch. Only optional fields can be removed. In a JSON file, write {"$remove": true}.
mod.data.patch("upgrades", "lab_core", { max = mod.REMOVE }) -- no level limit