Storage

The storage system is a reactive client-side key-value store. Values are lazy-loaded, can be updated from the server, and trigger callbacks when they change.

Accessing Storage

The global storage table (also available as KOJA.storage) is backed by a metatable. Simply reading a key registers an update listener for it:

local value = storage['myKey']

On the first read, the key is registered and its update event is subscribed. Subsequent reads return the cached value.

Getting a Value

-- Direct read
local myData = storage['playerStats']

-- Returns false if the key has never been set

Computed / Cached Values

Use the call syntax to compute and optionally cache a value with a timeout:

local value = storage(key, computeFunc, timeout)
Parameter
Type
Description

key

string

Storage key

computeFunc

function

Called to produce the value if it is not cached yet

timeout

number?

Milliseconds after which the cached value is cleared

Example

Reacting to Changes

Via event

Any time a key is updated (from the server or locally), koja-lib:callback_triggered fires:

Via key-specific event

Updating from the Server

Trigger the update event on the client to push a new value:

The client's storage['playerStats'] will be updated and all registered callbacks will fire.

Metadata Properties

Two properties are always available on the storage object:

Property
Value

storage.game

Result of GetGameName()

storage.resource

Result of GetCurrentResourceName()

Example — Live HUD Data

Last updated