Hello All,
I'm having trouble referencing a label in another function. At this point, I'm just learning and need a little help. Thanks to Zork for some skeleton code. Please code review and let me know why I'm getting nil reference on print(c.label:GetAlpha())
Line 58 works as expected.
Code:
-----------------------------
-- Learning
-- Specko
-----------------------------
-----------------------------
-- VARIABLES
-----------------------------
local wm = GetWindowManager()
local em = GetEventManager()
local print = d
local KillingBlow = ZO_Object:Subclass()
-----------------------------
-- FUNCTIONS
-----------------------------
function KillingBlow:New()
self.addonName = "KillingBlow"
self.addonList = {}
self:Initialize()
end
function KillingBlow:Initialize()
self.control = self:CreateControl()
self:InitializeEventManagement()
end
function KillingBlow:CreateControl()
local path = "EsoUI/Common/Fonts/univers67.otf"
local size = 25
local style = "thick-outline"
--main control
local c = wm:CreateTopLevelWindow()
c:SetDimensions(300,200)
c:SetAnchor(CENTER,GuiRoot,CENTER,0,0)
c:SetHidden(false)
c:SetMovable(false)
c:SetMouseEnabled(false)
c:SetClampedToScreen(true)
--label
c.label = wm:CreateControl(nil, c, CT_LABEL)
c.label:SetDimensions(300,200)
c.label:SetAnchor(CENTER, c, CENTER, 75, -150)
c.label:SetFont(path .. "|" .. size .. "|" .. style)
c.label:SetColor( 128,128,0,.5 )
c.label:SetHorizontalAlignment( CENTER )
c.label:SetVerticalAlignment( CENTER )
c.label:SetText ( c.label:GetAlpha() )
return c, c.label
end
function KillingBlow:labelScope()
print(c.label:GetAlpha())
end
--OnAddOnLoaded event trigger func
function KillingBlow:OnAddOnLoaded(event, name)
self.addonList[#self.addonList] = { event = event or "unknown", name = name or "unknown"}
end
--OnPlayerActivated event trigger func
function KillingBlow:OnPlayerActivated()
print("KillingBlow Loaded")
end
--init events func
function KillingBlow:InitializeEventManagement()
--event registering
em:RegisterForEvent(self.addonName.."_OnAddOnLoaded", EVENT_ADD_ON_LOADED, function(...) self:OnAddOnLoaded(...) end)
em:RegisterForEvent(self.addonName.."_OnPlayerActivated", EVENT_PLAYER_ACTIVATED, function(...) self:OnPlayerActivated(...) end)
em:RegisterForEvent(self.addonName.."_labelScope", EVENT_MOUNTED_STATE_CHANGED, function(...) self:labelScope(...) end)
end
-----------------------------
-- CALL
-----------------------------
KillingBlow:New()