Hey I'm trying to write a simple addon that would count how many times a player casted Nourish. I want to store data in a table indexed by played names, but the table is not being saved to SavedVariables.
I defined a SavedVariable in .toc file:
Code:
## SavedVariables: NourishCounter
And here's my addon:
Lua Code:
local frame = CreateFrame("FRAME", "AddonFrame");
frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
frame:RegisterEvent("ADDON_LOADED");
local function eventHandler(self, event, ...)
if event == "ADDON_LOADED" and arg1 == "NourishAddon" then
if not NourishCount then NourishCount = {} end
end
args = {...};
if args[2] == "SPELL_HEAL" then
if(args[10] == "Nourish") then
caster = args[4];
if NourishCount[caster] then
NourishCount[caster] = NourishCount[caster] + 1;
else
NourishCount[caster] = 1;
end
print(caster .. " count: " .. NourishCount[caster]);
end
end
end
frame:SetScript("OnEvent", eventHandler);
Within one login period the counter works fine, but the NourishCounter in saved vars file is always
nil. I tried using a regular number variable for just my own casts and it is saved correctly. I believe the problem is that the table keys are not defined when creating the table for the first time, but I don't know how to work around that.