Skip to content

mod.data

Read and change game data from Luau. The same operations as data/<kind>.json files. Writes work only while your mod loads.

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 loads
  • kind must be text
  • id must be text
mod.data.add("superweapons", "sunburst", {
base = "sunlance", name = "Sunburst", short = "BURST",
color = { 255, 140, 40 }, price = 500, cooldown = 200,
})

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 })

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 end
copy.war = 5
mod.data.replace("bots", "raider", copy)

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")

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)

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")
end

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)
end

server + client

Every kind name, sorted.

Returns { string }

mod.log(table.concat(mod.data.kinds(), ", "))

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