Skip to content

Configuration files

JSON files for plugin settings or state.

Functions

Balltze.openConfigFile

local config = Balltze.openConfigFile(path)

Opens a JSON file, creating it and its folders when they do not exist. A file that is not valid JSON is read as empty.

path is relative to the game's working folder, normally the game folder, not to the plugin folder, and it is not limited to the plugin folder. To keep the file with the plugin, build the path from Balltze.filesystem.getPluginPath():

local config = Balltze.openConfigFile(Balltze.filesystem.getPluginPath() .. "\\config.json")

BalltzeConfig

Keys are paths separated by dots: "window.size.width" is the width field inside size inside window.

Changes are kept in memory until save() is called. Nothing is saved automatically.

Method Returns Description
save() Writes the file.
load() Reads the file again, dropping unsaved changes.
exists(key) boolean Whether the key exists.
remove(key) Removes the key. The key must exist; check it with exists first.
getInteger(key) integer or nil The value, or nil when it is missing or not a number.
getNumber(key) number or nil
getString(key) string or nil
getBoolean(key) boolean or nil
set(key, value) Sets an integer, number, string or boolean. Strings that look like numbers, such as "5", are stored as numbers.

Example

local config = Balltze.openConfigFile(Balltze.filesystem.getPluginPath() .. "\\state.json")
local launches = (config:getInteger("launches") or 0) + 1
config:set("launches", launches)
config:save()