Skip to main content

config — Config API

Phase: All phases (most useful in Startup / Server)

A persistent key/value store backed by a single JSON file:

<gameDir>/atomicoffe/config.json

Unlike data (which is per-player), config is shared across the whole mod. Use it to store tunable parameters, feature flags, or anything that should survive server restarts.

Supported value types: string, number, boolean. Setting a key to nil removes it.


config.get(key)value | nil

Returns the stored value for key, or nil if not set.

local maxCoins = config.get("maxCoins") or 1000

config.set(key, value)

Stores a value and immediately saves to disk.

config.set("maxCoins", 500)
config.set("pvpEnabled", true)
config.set("welcomeMessage", "Welcome to the server!")

Setting a key to nil is equivalent to deleting it:

config.set("tempKey", nil)   -- removes the key

config.has(key)boolean

Returns true if the key exists in config.

if not config.has("initialized") then
-- first-time setup
config.set("initialized", true)
end

config.delete(key)

Removes the key and saves.

config.delete("oldSetting")

config.save()

Explicitly flushes the current config to disk. Normally not needed because config.set and config.delete auto-save.


Full Example

-- startup_scripts/config_init.lua
if not config.has("difficulty") then
config.set("difficulty", "normal")
config.set("maxPlayers", 20)
end

-- server_scripts/main.lua
local diff = config.get("difficulty")
server.setDifficulty(diff)