View Single Post
12-10-13, 03:35 PM   #1
dave20010
A Defias Bandit
Join Date: Dec 2013
Posts: 2
Saving Variables

I'm working on an AddOn but I can't seem to get certain variables to save in between sessions. I've looked at the wowwiki article, many posts on this forum, and random sites found through google. (Note: Most of the variable names and such in this article are changed)

.lua
Code:
local DB_DEFAULTS = {
		x = 0,
		y = 0,
		width = 100,
		height = 200,
}

local addon = CreateFrame("Frame", "MyAddon")
addon:RegisterEvent("ADDON_LOADED")

addon:SetScript("OnEvent", function(self, event, arg1)
	if event == "ADDON_LOADED" and arg1 == "MyAddon" then
	
		if (DB == nil) then
			print("hello") --Never gets printed
			DB = CopyDefaults(DB_DEFAULTS, DB) 
                        --Copies defaults if there is no saved data
		end
		
		Main() --Finishes frames
		self:UnregisterEvent("ADDON_LOADED")
		
	end
	
end)
.toc
Code:
## Interface: 50400
## Title: MyAddon
## Author: Dave20010
## Version: v1.0
## Notes: Addon for things
##SavedVariablesPerCharacter: DB

wat.lua
When I look at the SavedVariables .lua file in the WTF\Account\Accountname\Realmname\Charactername\SavedVariables folder, its contents are

Code:
DB = {
	["y"] = 949.9998168945313,
	["x"] = 2726.000244140625,
	["height"] = 350.0001220703125,
	["width"] = 221.9995574951172,
}
Where are these numbers coming from? And why doesn't the "if(DB == nil)" evaluate to nil if I delete the contents in the Addons SavedVariables file?
  Reply With Quote