Hi fellow forum users,
I was trying to create simple resource tracker addon using 'SavedVariables' and here's what I have done so far.
Code:
local ResourceTrackFrame = CreateFrame("Frame");
ResourceTrackFrame:RegisterEvent("PLAYER_LOGOUT");
local function ResourceTrackFrame_OnEvent(event, arg1)
if event == "PLAYER_LOGOUT" then
realm = GetRealmName();
name = UnitName("player");
_, englishClass = UnitClass("player");
_, currentAmount = GetCurrencyInfo(824);
if type(Resource) ~= "table" then
Resource = {};
end
if type(Resource[realm]) ~= "table" then
Resource[realm] = {};
end
if type(Resource[realm][name]) ~= "table" then
Resource[realm][name] = {};
end
Resource[realm][name]["Class"] = englishClass;
Resource[realm][name]["GarrisonResource"] = currentAmount;
end
end
ResourceTrackFrame:SetScript("OnEvent", ResourceTrackFrame_OnEvent);
The current problem is that the value that is being saved are always nil which I honestly don't get why.
According to wikia, it says that
"Variables are saved and loaded in the global environment". Would that be something related to this since I declared frame and function as local?