Originally Posted by Iyanga
As a side note:
Is there a reason why you wrap an anonymous function around yc:OnAddOnLoaded in line 30?
|
I'm using another addon as an example right now just to try and get this working. That's where that comes from.
I've got a new problem now in that even though I'm setting my handler for OnUpdate it's not being called afterwards. Code below, have bit ugly since I've been editing it back and forth while debugging.
Lua Code:
local yc = ZO_Object:Subclass()
local eventManager = GetEventManager()
local windowManager = GetWindowManager()
function yc:New()
yc.AddOnName = "YazClock"
yc.AddOnEventManager()
end
function yc:OnUpdate()
CHAT_SYSTEM:AddMessage("On UPdate")
yc.MainWindow.TimeLabel:SetText(GetDateStringFromTimestamp(GetTimeStamp()) .. " " .. GetTimeString())
end
function yc:OnAddOnLoaded(eventCode, addOnName)
CHAT_SYSTEM:AddMessage("OnLoaded")
end
function yc:PlayerActivated()
CHAT_SYSTEM:AddMessage("Test")
if (yc.MainWindow == nil) then
yc.MainWindow = windowManager:CreateTopLevelWindow(yc.AddOnName .. "_MainWindow")
yc.MainWindow:SetDimensions(200, 42)
yc.MainWindow:SetAnchor(CENTER, GuiRoot, TOPLEFT, 0, 0)
CHAT_SYSTEM:AddMessage("Setting handler")
yc.MainWindow.TimeLabel = windowManager:CreateControl(yc.AddOnName .. "_TimeLabel", yc.MainWindow, CT_LABEL)
yc.MainWindow.TimeLabel:SetFont("ZoFontAnnounceMessage")
yc.MainWindow.TimeLabel:SetDimensions(200, 42)
yc.MainWindow.TimeLabel:SetText("Test")
yc.MainWindow.TimeLabel:SetHandler("OnUpdate", function(self, timerun)
CHAT_SYSTEM:AddMessage("OnUpdate Fired")
end)
end
end
function yc:AddOnEventManager()
CHAT_SYSTEM:AddMessage("Test2")
eventManager:RegisterForEvent(yc.AddOnName .. "_AddOnLoaded", EVENT_ADD_ON_LOADED, function(...) yc:OnAddOnLoaded(...) end)
eventManager:RegisterForEvent(yc.AddOnName .. "_PlayerActivated", EVENT_PLAYER_ACTIVATED, function(...) yc.PlayerActivated(...) end)
end
yc:New()
I've had the SetHandler also set to:
lua Code:
yc.MainWindow.TimeLabel:SetHandler("OnUpdate", OnUpdate)
-- and
yc.MainWindow.TimeLabel:SetHandler("OnUpdate", function(...) yc:OnUpdate(...) end)
Originally Posted by Seerah
To clarify why it wasn't working, in your first code example (in the first post), yc is not a control/object. Script handlers can only be set on controls.
|
Yeah thanks Seerah for wording it better!