util.monitor.has

Client

Checks whether a stat exists, either native or custom


Syntax

local result = util.monitor.has(
    id
)

Accepts both native and custom stat identifiers.

Parameters

TypeNameDescription
util.monitor.stat_native | stringidStat to look up:
• When util.monitor.stat_native - checks a native stat by enum value
• When string - checks a custom stat by its registered id

Returns

TypeNameDescription
boolresulttrue if the stat exists, false otherwise

Examples

Check for a native stat
if util.monitor.has(util.monitor.stat_native.TIME_FPS) then
    core.engine.print("info", "FPS stat is available")
end
Check for a custom stat before reading it
if util.monitor.has("my_resource:entity_count") then
    core.engine.print("info", "Entity count:", util.monitor.get("my_resource:entity_count"))
end
Guard registration with an existence check
if not util.monitor.has("my_resource:cache_size") then
    util.monitor.register("my_resource:cache_size", "Cache Size", function()
        return cache.byte_size()
    end, util.monitor.stat_format.MEMORY)
end

On this page