Sharp Aion2 Lua SDK
API reference

scriptLua table

Run background work, pause it, and save module values.

The script table is available in every Lua script. Background workers and saved values belong to a loaded module. See lifecycle for callback timing.

script.start_worker(fn)

Parameters: fn is a function that performs work and can call script.sleep. Start one worker per module from top-level code or a callback.

Returns: true when started, or nil, error if no worker can start or one is already running. The worker stops when its module unloads.

function on_start()
    local ok, err = script.start_worker(function()
        while true do
            local level = game.local_level()
            if level then log.info("Level " .. level) end
            script.sleep(2000)
        end
    end)
    if not ok then log.warn(err) end
end

script.sleep(milliseconds)

Parameters: milliseconds is an integer from 0 to 3,600,000.

Returns: Pauses the current worker before its next step. Calling it outside a worker raises an error.

script.sleep(500)

script.state_get(key)

Parameters: key is a module value name of 1–64 letters, digits, _, or -.

Returns: The saved string, nil when no value exists, or nil, error if it cannot be read. Instant scripts receive nil, error.

local previous = script.state_get("counter")
log.info(previous or "0")

script.state_set(key, value)

Parameters: key follows the same naming rule as state_get. value is a nonempty string of at most 64 KiB.

Returns: true when saved, or nil, error on failure. Values persist across module reloads.

local ok, err = script.state_set("counter", "1")
if not ok then log.warn(err) end