Skip to content

Option

Option helpers for Lilia user settings, including registration, lookup, localization, persistence, and configuration menu display.


Overview

The option library centralizes user-facing settings under `lia.option`. It stores registered option metadata and values, infers option types from defaults, localizes labels, descriptions, categories, and selectable values, persists option values to `data/lilia/options.json`, and builds the configuration menu page used to edit registered options.

lia.option.add(key, name, desc, default, callback, data)View Source

Purpose

Registers an option and stores its display metadata, default value, callback, type information, and configuration data.

Realm

Shared

Parameters

string key The unique option identifier.

string name The display name or language token for the option.

string desc The display description or language token for the option.

any default The default value used when no saved value exists.

function callback optional Optional function called with the old and new values when the option changes.

table data Option metadata such as category, type, min, max, decimals, options, visible, shouldNetwork, and isQuick.

Example Usage

  lia.option.add("exampleOption", "@exampleOption", "@exampleOptionDesc", true, nil, {
      category = "@core",
      type = "Boolean"
  })

lia.option.getDisplayName(key)View Source

Purpose

Returns the localized display name for a registered option.

Realm

Shared

Parameters

string key The unique option identifier.

Returns

string The localized option display name, or the key when the option is not registered.

Example Usage

  local name = lia.option.getDisplayName("descriptionWidth")

lia.option.getDisplayDesc(key)View Source

Purpose

Returns the localized display description for a registered option.

Realm

Shared

Parameters

string key The unique option identifier.

Returns

string The localized option description, or an empty string when the option is not registered.

Example Usage

  local desc = lia.option.getDisplayDesc("descriptionWidth")

lia.option.getDisplayCategory(key)View Source

Purpose

Returns the localized display category for a registered option.

Realm

Shared

Parameters

string key The unique option identifier.

Returns

string The localized option category, or the localized misc category when none is set.

Example Usage

  local category = lia.option.getDisplayCategory("descriptionWidth")

lia.option.getOptions(key)View Source

Purpose

Returns normalized and localized selectable values for a registered table option.

Realm

Shared

Parameters

string key The unique option identifier.

Returns

table A table of selectable option entries containing label, rawLabel, and value fields.

Example Usage

  local options = lia.option.getOptions("weaponSelectorPosition")

lia.option.set(key, value)View Source

Purpose

Updates a registered option value, runs its callback, emits option change hooks, and saves option values.

Realm

Shared

Parameters

string key The unique option identifier.

any value The new option value.

Example Usage

  lia.option.set("drawItemHoverInfo", false)

lia.option.get(key, default)View Source

Purpose

Returns the current value for a registered option.

Realm

Shared

Parameters

string key The unique option identifier.

any default Fallback value returned when the option is not registered and has no stored default.

Returns

any The current option value, the registered default value, or the provided fallback default.

Example Usage

  local enabled = lia.option.get("drawItemHoverInfo", true)

lia.option.save()View Source

Purpose

Saves all registered option values to `data/lilia/options.json`.

Realm

Shared

Example Usage

  lia.option.save()

lia.option.load()View Source

Purpose

Loads saved option values from `data/lilia/options.json`, or initializes and saves defaults when no option file exists.

Realm

Shared

Example Usage

  lia.option.load()

Hooks

Library-specific hooks documented for this library.


InitializedOptions()View Source

Purpose

Runs after saved option values are loaded, or after defaults are initialized and saved when no option file exists.

Realm

Shared


OptionAdded(key, option)View Source

Purpose

Runs after an option is registered with `lia.option.add`.

Realm

Shared

Parameters

string key The unique option identifier.

table option The stored option data table created for the key.


OptionChanged(key, oldValue, newValue)View Source

Purpose

Runs after `lia.option.set` changes a registered option value.

Realm

Shared

Parameters

string key The unique option identifier.

any oldValue The value before the change.

any newValue The value after the change.


OptionReceived(client, key, value)View Source

Purpose

Runs on the server when a changed option is marked for networking.

Realm

Server

Parameters

Player client optional The player associated with the networked option change, or nil when triggered directly by `lia.option.set`.

string key The unique option identifier.

any value The networked option value.


ThirdPersonToggled(enabled)View Source

Purpose

Runs when the `thirdPersonEnabled` option changes.

Realm

Client

Parameters

boolean enabled True when third-person view was enabled, false when it was disabled.