Skip to content

Files, JSON and other mods

Read your own files, parse JSON, load your own modules and share a table with mods that depend on you.

server + client

Parses JSON.

Parameter Type
text string JSON text.

Returns the value

Raises

  • json.decode expects text
  • json.decode:
local t = mod.json.decode('{ "wave": 3 }')
mod.log(t.wave)

server + client

Encodes plain data: numbers, text, booleans, and tables up to 6 levels deep and 2000 entries.

Parameter Type
value any Plain data.

Returns string

Raises

  • json.encode: only plain data (numbers, text, booleans, tables)
mod.log(mod.json.encode({ wipes = 3, best = "Nuke" }))

server + client

The text of a file inside your mod (1 MB at most), or nil if it is not there.

Parameter Type
path string Relative to your mod folder.

Returns string?

Raises

  • bad path
local cfg = mod.read("data/ships.json")
if cfg then mod.log(#cfg, "bytes") end

server + client

Same as require: loads a module from your own mod. ./helper finds helper.luau (or .luauc), ./dir finds dir/init.luau. Each module runs once; cycles and paths outside the mod raise.

Parameter Type
path string ./name, relative to the mod root.

Returns what the module returns

local ok = pcall(mod.require, "./not_here")
assert(not ok)

server + client

That mod’s exports table (live: read it, do not change it), or nil if it is not active. The mod must be in your requires or load_after.

Parameter Type
modId string A mod id from your manifest.

Returns table?

Raises

  • ' is not in requires or load_after
-- mod.json: "load_after": ["solar_flare"]
local flare = mod.use("solar_flare")
if flare then mod.log("Solar Flare is here") end

server + client table

Anything you put here is what mod.use returns to mods that depend on you.

mod.exports.version = 2
mod.exports.greet = function(name)
return "HELLO " .. name
end