Thread Tools Display Modes
Prev Previous Post   Next Post Next
06-26-16, 11:59 PM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
(About SavedVariable) What would be the problem with this code?

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

WoWInterface » Developer Discussions » Lua/XML Help » (About SavedVariable) What would be the problem with this code?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off