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)
Code:
local mapId = 988
local enterHandler = function(oldMapId, newMapId)
CHAT_ROUTER:AddSystemMessage(string.format("Entered %s from %s", GetMapNameById(newMapId), GetMapNameById(oldMapId)))
end
local exitHandler = function(oldMapId, newMapId)
CHAT_ROUTER:AddSystemMessage(string.format("Left %s to %s", GetMapNameById(oldMapId), GetMapNameById(newMapId)))
end
LibHandler:MapChange(mapId ,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