Stats API

Store and manage script statistics for reporting.

Functions

set

stats:set(key: string, value: string|number) -> ()

Set a single statistic.

Parameters:

ParameterTypeRequiredDescription
keystringYesStatistic key
valuestringnumberYes

Example:

stats:set("items_gathered", 100)
stats:set("status", "Running")

set_many

stats:set_many(table: table) -> ()

Set multiple statistics at once.

Parameters:

ParameterTypeRequiredDescription
tabletableYesKey-value pairs

Example:

stats:set_many({
    items_gathered = 100,
    xp_gained = 5000,
    runtime = "1:30:45"
})

get

stats:get(key: string) -> string|number?

Get a statistic value.

Parameters:

ParameterTypeRequiredDescription
keystringYesStatistic key

Returns:

  • string|number? - Value, or nil if not set

get_all

stats:get_all() -> table

Get all statistics.

Returns:

  • table - All key-value pairs

clear

stats:clear(key: string) -> ()

Clear a specific statistic.

Parameters:

ParameterTypeRequiredDescription
keystringYesStatistic key

clear_all

stats:clear_all() -> ()

Clear all statistics.


Common Patterns

Tracking Progress

local function track_gathering()
    local items_gathered = stats:get("items_gathered") or 0
    items_gathered = items_gathered + 1
    stats:set("items_gathered", items_gathered)
end

Session Statistics

local script_start = os.time()

local function update_session_stats()
    local runtime = os.time() - script_start
    local hours = math.floor(runtime / 3600)
    local minutes = math.floor((runtime % 3600) / 60)
    local seconds = runtime % 60
    
    stats:set_many({
        runtime = hours .. "h " .. minutes .. "m " .. seconds .. "s",
        status = "Running"
    })
end

Performance Metrics

local function track_performance()
    stats:set_many({
        items_per_minute = 60,
        clicks = 1200,
        elapsed = "1:30:00"
    })
end

Related APIs

  • Logger API - Logging messages
  • Paint API - On-screen overlays