ax.util¶
Source: gamemode/framework/util/util_store.lua
Utility helpers used across the Parallax framework (printing, file handling, text utilities, etc.).
Section: store
Documented functions: 16
Functions¶
ax.util:CreateStore(spec, oldStore)store:_setupNetworking()store:Add(key, type, default, data)store:Get(...)store:GetAllByCategory(category)store:GetAllCategories()store:GetAllDefinitions()store:GetData(key)store:GetDefault(key)store:HandleConfigChange(regEntry, oldValue, newValue, key)store:Load()store:Save()store:Set(key, value, bNoSave, bNoCallback)store:SetDefault(key, value)store:SetToDefault(key)store:Sync(target)
ax.util:CreateStore(spec, oldStore)¶
Create a new store instance.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
spec |
table |
Store specification with fields: - name (string): identifier, e.g. "config" or "option" - authority (string): "server" or "client" — side that persists values - path (string): JSON file path under DATA for persistence - net (table): net channel names (init, set, sync, request as applicable) |
oldStore |
table |
Optional existing store to migrate data from during hot-reload |
Returns
table: Store object with methods for registration, get/set, IO, and networking
Usage
local store = ax.util:CreateStore({
name = "config",
authority = "server",
path = ax.util:BuildDataPath("config", { human = true }),
net = { init = "config.init", set = "config.set" }
})
store:_setupNetworking()¶
Internal: register net channels and hooks for networking. Wires up init/set/sync/request handlers for config and option.
Realm: shared
store:Add(key, type, default, data)¶
Add a new setting definition to the store.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Setting key |
type |
any |
ax.type data type (e.g. ax.type.number) |
default |
any |
Default value |
data |
table |
Additional metadata (category, bNoNetworking, min/max/decimals, populate=function, OnChanged=function) |
Returns
boolean: True if added, false on invalid params
store:Get(...)¶
Get a value from the store. For option on server, supports per-player reads when the first arg is a Player.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
... |
any |
Key and optional default; or (player, key, fallback) for option |
Returns
any: Value or default
store:GetAllByCategory(category)¶
Get all definitions where the category matches the given string. Case-insensitive partial matching via ax.util:FindString.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
category |
string |
Category filter |
Returns
table: Map of key -> definition table
store:GetAllCategories()¶
Get a list of all categories present in the registry.
Realm: shared
Returns
table: Array of category names
store:GetAllDefinitions()¶
Get a copy of all registered definitions.
Realm: shared
Returns
table: Map of key -> definition table
store:GetData(key)¶
Get the metadata table for a registered key.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Setting key |
Returns
table|nil: Copy of data table or nil if unknown
store:GetDefault(key)¶
Get the default value for a key.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Setting key |
Returns
any: Default value or nil if unknown
store:HandleConfigChange(regEntry, oldValue, newValue, key)¶
Invoke a key's OnChanged handler if present.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
regEntry |
table |
Registry entry for the key |
oldValue |
any |
Previous value |
newValue |
any |
New value |
key |
string |
Setting key |
store:Load()¶
Load persisted values from disk. Only runs on the authority side set by spec.authority.
Realm: shared
Returns
boolean: True on success, false if no file or invalid
store:Save()¶
Save current values to disk. Only runs on the authority side set by spec.authority.
Realm: shared
Returns
boolean: True on success
store:Set(key, value, bNoSave, bNoCallback)¶
Set a value in the store. Coerces to the registered type, clamps numbers, validates array choices, triggers OnChanged and global hooks, persists, and handles networking.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Setting key |
value |
any |
New value |
bNoSave |
boolean |
Optional; when true, skip persistence |
bNoCallback |
boolean |
Optional; when true, skip OnChanged and hooks |
Returns
boolean: True if the value changed, false otherwise along with a reason
store:SetDefault(key, value)¶
Set the default value for a key.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Setting key |
value |
any |
Default value |
Returns
boolean: True on success
store:SetToDefault(key)¶
Set's a value to its default.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Setting key |
Returns
boolean: True if the value changed, false otherwise
store:Sync(target)¶
Sync networked keys. For config on server: sends initial values to clients (or a target). For option on client: sends local preferences to the server.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
target |
any |
Optional player or table of players (server-side config) |