Quantcast
Download
(3 Kb)
Download
Updated: 07/21/21 08:24 PM
Compatibility:
Waking Flame (7.1.5)
Blackwood (7.0.5)
Updated:07/21/21 08:24 PM
Created:07/21/21 08:24 PM
Monthly downloads:577
Total downloads:604
Favorites:0
MD5:
7.0.5
LibHandler
Version: 0.0.1
by: zelenin [More]
Work In Progress (unstable API)

a collection of some handlers used in addon development

- conditional handler

The condition is checked every 1000 ms until it returns true. Then the task is executed

Code:
local condition = function()
    -- checking something
    return true
end

local task = function()
    -- do something
end

local timeout = 1000

LibHandler:Condition(condition, task, timeout)

- zone change handler

Handlers are executed when entering and exiting a certain zone.

Code:
local zoneId = 1263 -- Rockgrove
local enterHandler = function(oldZoneId, newZoneId)
    CHAT_ROUTER:AddSystemMessage(string.format("Entered %s zone from %s zone", GetZoneNameById(newZoneId), GetZoneNameById(oldZoneId)))
end
local exitHandler = function(oldZoneId, newZoneId)
    CHAT_ROUTER:AddSystemMessage(string.format("Left %s zone to %s zone", GetZoneNameById(oldZoneId), GetZoneNameById(newZoneId)))
end

LibHandler:ZoneChange(zoneId,enterHandler, exitHandler)

- limiters

Code:
local timeThreshold = 100 -- ms
--local repeatable = true -- executes the last task every 100 ms
local repeatable = false -- executes the last task if there is no new task for the last 100 ms

local limiter = LibHandler:Limiter(function(arg1, arg2, arg3, ..., argN)
    CHAT_ROUTER:AddSystemMessage(arg1)
end, timeThreshold, repeatable)

local limiterWithDependency = LibHandler:LimiterWithDependency(function(arg1, arg2, arg3, ..., argN)
    CHAT_ROUTER:AddSystemMessage(arg1)
end, timeThreshold, repeatable)

for i = 0, 10 do
    local timeout =i*40
    local arg1 = string.format("i: %d timeout: %d", i, timeout)
    local dependency = 1 -- any number, string or function returning number or string
    zo_callLater(function()
        limiter:Trigger(arg1, arg2, arg3, ..., argN)
        limiterWithDependency:Trigger(dependency, arg1, arg2, arg3, ..., argN)
    end, timeout)
end
There have been no comments posted to this file.
Be the first to add one.



Category Jump: