The following code attempts to store the characters name and current count of Prismatic Manapearls into table a once it recognizes that the add-on has been loaded.
The issue I am having is that when iterating through the table, or even just after getting the value, it always returns CurrentAmount as 0. As a test I also iterated through all currencies and their CurrentAmount values, and surprising they were all 0.
Is the CurrencyAmount loaded at a later time?
Code:
local frame = CreateFrame("FRAME");
frame:RegisterEvent("ADDON_LOADED");
frame:RegisterEvent("PLAYER_LOGOUT");
function frame:OnEvent(event, arg1)
if event == "ADDON_LOADED" and arg1 == "MyPearls" then
if PearlCount == nil then
a = {};
else
a = PearlCount;
end
CurrentAmount = select(2, GetCurrencyInfo(1721));
a[GetUnitName("player", false)] = CurrentAmount;
print(CurrentAmount); -- to test its contents
elseif event == "PLAYER_LOGOUT" then
PearlCount = a;
end
end
frame:SetScript("OnEvent", frame.OnEvent);
SLASH_HOWMANYPEARLS1 = "/pearls";
SlashCmdList["HOWMANYPEARLS"] = function()
for name, pCount in pairs(a) do
print(name, " -- ", pCount)
end
end
Thanks for any info you can provide.