View Single Post
11-30-19, 09:13 PM   #3
fail2reap
A Murloc Raider
Join Date: Nov 2019
Posts: 3
Originally Posted by myrroddin View Post
Instead of ADDON_LOADED, try PLAYER_LOGIN. I assume PearlCount is your saved variable? CurrentAmount should be a local variable.
That did the trick. Seems only after this event is fired, do the values for the player actually get loaded.

Here's the revised code.
Code:
local frame = CreateFrame("FRAME"); 
frame:RegisterEvent("ADDON_LOADED"); 
frame:RegisterEvent("PLAYER_LOGIN");
frame:RegisterEvent("PLAYER_LOGOUT");

function frame:OnEvent(event, arg1)    
    if event == "ADDON_LOADED" and arg1 == "HeyThere" then
        if PearlCount == nil then
            a = {};
        else
            a = PearlCount;
        end

    elseif event == "PLAYER_LOGIN" then
        local _, CurrentAmount = GetCurrencyInfo(1721);
        a[GetUnitName("player", false)] = CurrentAmount;

    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
  Reply With Quote