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.
mod.json.decode(text)
Section titled “mod.json.decode(text)”server + client
Parses JSON.
| Parameter | Type | |
|---|---|---|
text |
string |
JSON text. |
Returns the value
Raises
json.decode expects textjson.decode:
local t = mod.json.decode('{ "wave": 3 }')mod.log(t.wave)mod.json.encode(value)
Section titled “mod.json.encode(value)”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" }))mod.read(path)
Section titled “mod.read(path)”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") endmod.require(path)
Section titled “mod.require(path)”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)mod.use(modId)
Section titled “mod.use(modId)”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") endmod.exports
Section titled “mod.exports”server + client table
Anything you put here is what mod.use returns to mods that depend on you.
mod.exports.version = 2mod.exports.greet = function(name) return "HELLO " .. nameend