I'm keeping this as simple as I can. This code is just a little counter that uses a right mouse button click to open a window that has a counter in it. The code works it just doesn't save the count. So my question is what is wrong with this code?
Lua Code:
-- First I will start with my saved variable table.
local ZCountSave = {
["Count"] = {
["ClickedCount"] = 0,
}
}
-- Next I will create my button to pull up the counter.
ZCountButton = CreateFrame("Button","ZCountButton",UIParent,"UIPanelButtonTemplate")
ZCountButton:SetPoint("CENTER",0,0)
ZCountButton:SetWidth(30)
ZCountButton:SetHeight(30)
ZCountButton:SetText("ZC")
ZCountButton:SetMovable(true)
ZCountButton:RegisterForDrag("LeftButton")
ZCountButton:SetScript("OnDragStart",ZCountButton.StartMoving)
ZCountButton:SetScript("OnDragStop",ZCountButton.StopMovingOrSizing)
-- Now I'm going to create my frame that will have my counter inside of it.
ZCountBoxFrame = CreateFrame("Frame")
ZCountBoxFrame:SetPoint("CENTER", 0, 0)
ZCountBoxFrame:SetBackdrop(StaticPopup1:GetBackdrop())
ZCountBoxFrame:SetHeight(300)
ZCountBoxFrame:SetWidth(300)
ZCountBoxFrame:Hide(true)
ZCountBoxFrame:SetMovable(true)
ZCountBoxFrame:EnableMouse(true)
ZCountBoxFrame:RegisterForDrag("LeftButton")
ZCountBoxFrame:SetScript("OnDragStart",ZCountBoxFrame.StartMoving)
ZCountBoxFrame:SetScript("OnDragStop",ZCountBoxFrame.StopMovingOrSizing)
-- Next we need to create a function that can open our ZCountBoxFrame.
ZCountButton:RegisterForClicks("AnyUp")
ZCountButton:SetScript("OnClick", function(self, button, ...)
if (button == "RightButton") then
if ZCountBoxFrame:IsShown() then
ZCountBoxFrame:Hide()
else
ZCountBoxFrame:Show()
end
end
end)
-- Now let's make the counter which will be inside our ZCountBoxFrame
ZCounterButton = CreateFrame("Button","ZCounterButton",ZCountBoxFrame,"UIPanelButtonTemplate")
ZCounterButton:SetPoint("CENTER",0,0)
ZCounterButton:SetWidth(80)
ZCounterButton:SetHeight(30)
ZCounterButton:SetText("Count: ")
-- Now that we have our Counter Button we need to create a function that will count a number up, down, and back to zero.
ZCounterButton:RegisterForClicks("AnyUp")
ZCounterButton:SetScript("OnClick", function(self, button, ...)
if (button == "LeftButton") then
ZCountSave.Count.ClickedCount = ZCountSave.Count.ClickedCount + 1
ZCounterButton:SetText("Count: "..ZCountSave.Count.ClickedCount)
end
end)
-- Now to put in the Addon Loaded so it can save some things for us.
local ZLoFrame=CreateFrame("Frame")
ZLoFrame:RegisterEvent("ADDON_LOADED")
ZLoFrame:SetScript("OnEvent",function(self,event,...)
if event=="ADDON_LOADED" and (...)==ZCount then
if ZCountSave.Count.ClickedCount ~= 0 then
ZCounterButton:SetText("Completed: "..ZCountSave.Count.ClickedCount)
end
self:UnregisterEvent("ADDON_LOADED")
end
end)