Thread Tools Display Modes
11-01-10, 02:11 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
saving tables as variables in the saved variables

Why is it exactly that when i try to dump a table to the saved variables it only picks up some of the table entry's?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
11-01-10, 02:55 PM   #2
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
well make sure its saving correctly

in your toc you need ##SavedVariables: or ##SavedVariablesPerCharacter:


and you dont have to save them, they are just active

you could have a addon that said

Code:
if event == "VARIABLES_LOADED" then
  myAddonDB.timesLoggedIn = myAddonDB.timesLoggedIn + 1
end
and be done with it.

also make sure that you know that

Code:
local table1, table2 = {1,2,3}, {4,5,6}
table1 = table2
wipe(table2)
for k,v in ipairs(table1) do
    print(k,v)
end
will output noting because when you set a table equal to another table, you dont add the values or set the values equal to each other, you save the reference pointer to the table.

Another thing is that your saved variables dont have to be tables, you could have MyAddonTimesLogged, MyAddonTimesDied and just have 2 numeric values.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
11-01-10, 03:11 PM   #3
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Well what im trying to do is... i have a chunk of code that deals with moving frames. It used to just build a table when the game loaded and those were your moveable frames. well... im trying to make things so that i can add/remove frames to that table from in game and have it save my additions/removels per session. I added another savevar to the .toc called GMoveableFrames. I tried to switch everything from that table to the saved variables but the big problem is on log out it only writes half of the frames it should to the saved variable file so on the next load up it does not load all the frames it should to the frame mover. I know this code might be a little confusing with out posting some of the other lua's in the addon but im pretty sure all important parts are there.

Code:
local addonName, addon = ...

addon:RegisterDefaultSetting("lockFrames", false)


--[[-----------------------------------------------------------------------------
Frames to allow moving and saving
-------------------------------------------------------------------------------]]
--["FrameName"] =	false  - move the frame
--true   - move the frame's parent instead
--string - move the named frame instead


function addon:DefaultMoveableFrames()
GMoveableFrames = {
	['MiniMapLFGFrame'] = false,
	['MiniMapBattlefieldFrame'] = false,
	['ShardBarFrame'] = false,
	['BNToastFrame'] = false,
	['RuneFrame'] = false,
	['SpellBookFrame'] = false,
	['QuestLogFrame'] = false,
	['FriendsFrame'] = false,
	['LFGParentFrame'] = false,
	['KnowledgeBaseFrame'] = true,
	['MerchantFrame'] = false,
	['MailFrame'] = false,
	['DressUpFrame'] = false,
	['TaxiFrame'] = false,
	['QuestLogFrame'] = false,
	['PaperDollFrame'] = true,
	['PVPFrame'] = false,
	['WatchFrameHeader'] = true,
	['VehicleMenuBar'] = false,
	['InspectFrame'] = false,
	['PlayerTalentFrame'] = false,
	['AchievementFrame'] = false,
	['AchievementFrameHeader'] = true,
	['AchievementFrameCategoriesContainer'] = 'AchievementFrame',
	['GlyphFrame'] = 'PlayerTalentFrame',
	['CalendarFrame'] = false,
	['GrimUIPlayerFrame'] = false,
	['GrimUIPartyFrame1'] = false,
	['GrimUIPartyFrame2'] = false,
	['GrimUIPartyFrame3'] = false,
	['GrimUIPartyFrame4'] = false,
	['GrimExpBar'] = false,
	['GrimRepBar'] = false,
	['GDevBar'] = false,
}


for id = 1, NUM_CONTAINER_FRAMES do
	GMoveableFrames['ContainerFrame' .. id] = false
end

end


--[[-----------------------------------------------------------------------------
Frame hooking
-------------------------------------------------------------------------------]]
local hookedFrame, parentFrame, movedFrames, oldPoint, oldX, oldY = { }, { }

local function GetRelativePosition(frame)
	local _, _, uiWidth, uiHeight = UIParent:GetRect()
	local left, bottom, width, height = frame:GetRect()
	if bottom + height / 2 >= uiHeight / 2 then
		if left + width / 2 >= uiWidth / 2 then
			return 'TOPRIGHT', left + width - uiWidth - 1, bottom + height - uiHeight - 1
		else
			return 'TOPLEFT', left, bottom + height - uiHeight - 1
		end
	elseif left + width / 2 >= uiWidth / 2 then
		return 'BOTTOMRIGHT', left + width - uiWidth - 1, bottom
	end
	return 'BOTTOMLEFT', left, bottom
end

local function OnShow(self)
	local frame = parentFrame[self] or self
	local position = movedFrames[frame:GetName()]
	if position then
		addon:UnlockFrame(frame)
		frame:ClearAllPoints()
		frame:SetPoint(unpack(position))
		addon:LockFrame(frame)
	end
end

local function OnMouseDown(self, button)
	if button ~= 'LeftButton' or addon.settings.lockFrames then return end
	if IsControlKeyDown() and button == 'LeftButton' then
	local frame = parentFrame[self] or self
	oldPoint, oldX, oldY = GetRelativePosition(frame)
	addon:UnlockFrame(frame)
	frame:StartMoving()
	end
end

local function OnMouseUp(self, button)
	if button ~= 'LeftButton' or not oldPoint then return end
	local frame = parentFrame[self] or self
	frame:StopMovingOrSizing()
	addon:LockFrame(frame)
	local point, x, y = GetRelativePosition(frame)
	if point ~= oldPoint or x ~= oldX or y ~= oldY then
		movedFrames[frame:GetName()] = { point, 'UIParent', x, y }
	end
	oldPoint, oldX, oldY = nil, nil, nil
end

local HookFrame
function HookFrame(name, parent)
	if hookedFrame[name] then return true end
	local frame = _G[name]
	if not frame then return end
	if parent then
		if type(parent) == 'string' then
			parent = _G[parent]
		else
			parent = frame:GetParent()
		end
		if not parent then return end
		HookFrame(parent:GetName())
		while(parentFrame[parent]) do
			parent = parentFrame[parent]
		end
		parentFrame[frame] = parent
	elseif not name:match("^" .. addonName) then
		frame:HookScript('OnShow', OnShow)
	end
	frame:EnableMouse(true)
	frame:EnableKeyboard(true)
	frame:SetMovable(true)
	frame:SetClampedToScreen(false)
	frame:HookScript('OnMouseDown', OnMouseDown)
	frame:HookScript('OnMouseUp', OnMouseUp)
	hookedFrame[name] = true
	if movedFrames[name] and frame:IsShown() then
		OnShow(frame)
	end
	return true
end

--[[-----------------------------------------------------------------------------
Initialize
-------------------------------------------------------------------------------]]
addon.RegisterEvent("MoveFrames-Initialize", 'PLAYER_LOGIN', function(self, event)
	addon.UnregisterEvent(self, event)

	movedFrames = addon.settings.movedFrames
	if type(movedFrames) ~= 'table' then
		movedFrames = { }
		addon.settings.movedFrames = movedFrames
	end
	addon:RegisterDefaultSetting("movedFrames", true)										-- Prevent it from being removed on PLAYER_LOGOUT
	
	local function HookFrames(self, event)
		if not GMoveableFrames then
			addon:DefaultMoveableFrames()
			end
		for name, parent in pairs(GMoveableFrames) do
			if HookFrame(name, parent) then
				GMoveableFrames[name] = nil
			end
		end
		if next(GMoveableFrames) then return end
		addon.UnregisterEvent(self, event)
	end

	addon.RegisterEvent("MoveFrames-Hook", 'ADDON_LOADED', HookFrames)
	HookFrames("MoveFrames-Hook", 'ADDON_LOADED')
	
end)


--[[-----------------------------------------------------------------------------
in game add remove functions
-------------------------------------------------------------------------------]]
function addon:AddMoveableFrame()
	
end

function addon:RemMoveableFrame()
	
end
what em i doing wrong?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
11-01-10, 03:21 PM   #4
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
well, what does SetDefaultSettings (or whatever the function was called on line 3 or so) do? I dont see it in your copied code... does a VARIABLES_LOADED event happen to remove the defalut settings and set up your saved settings? I forget if PLAYER_LOGIN comes before or after, but if its after, PLAYER_LOGIN is a just as good.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
11-01-10, 03:30 PM   #5
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
this is the lua that contains the register settings information part of what makes this tricky is im using Vrul's LOD settings lib and AceGUI.
I also have the same problem with only pulling 8 of the table entrys when i try to make the config panel list out the current frames registered for moveing.

Idealy the end product is that in game youll have panel on the config panel that has a add/remove frame button and shows you a list of current entrys.
Code:
local addonName, addon = ...

local defaults = {
	class = true
}

--[[-----------------------------------------------------------------------------
RegisterDefaultSetting - Allow modules to set their defaults
-------------------------------------------------------------------------------]]
function addon:RegisterDefaultSetting(key, value)											-- Use caution if using this after ADDON_LOADED
	defaults[key] = value
end

--[[-----------------------------------------------------------------------------
Load settings, apply version conversions as needed, and link to defaults
-------------------------------------------------------------------------------]]
addon.RegisterEvent("Settings-Load", 'ADDON_LOADED', function(self, event, name)
	if name ~= addonName then return end
	addon.UnregisterEvent(self, event)

	local name, class = UnitClass('player')
	name = UnitName('player')
	local realm = GetRealmName()

	local settings = _G[addonName .. "Settings"]
	if type(settings) ~= 'table' then
		settings = { }
		_G[addonName .. "Settings"] = settings
	end
	if type(settings[realm]) ~= 'table' then
		settings[realm] = { }
	end
	if type(settings[realm][name]) ~= 'table' then
		settings[realm][name] = { class = class }
	end

	settings.version = nil																			-- Reset value on logout (so can iterate over data without issue)
	addon.settings = setmetatable(settings[realm][name], { __index = defaults })
	return settings
end)

function addon:ResetWTF()
	local name, class = UnitClass('player')
	name = UnitName('player')
	local realm = GetRealmName()
	local settings = _G[addonName .. "Settings"]
	if type(settings) == 'table' then
		settings = { }
		_G[addonName .. "Settings"] = settings
	end
	if type(settings[realm]) == 'table' then
		settings[realm] = { }
	end
	settings.version = nil																			-- Reset value on logout 
	return settings 
end

--[[-----------------------------------------------------------------------------
Remove unused settings or settings that are the same as defaults
-------------------------------------------------------------------------------]]
addon.RegisterEvent("Settings-Unload", 'PLAYER_LOGOUT', function()
	local settings = addon.settings
	for key, value in pairs(settings) do
		if value == defaults[key] or defaults[key] == nil then
			settings[key] = nil
		end
	end
	_G[addonName .. "Settings"].version = GetAddOnMetadata(addonName, 'Version')
end)

--[[-----------------------------------------------------------------------------
LOD Configuration
-------------------------------------------------------------------------------]]
local LOA = LibStub and LibStub('LibOptionsAssist-1.0', true)
if not (LOA and select(2, GetAddOnInfo(addonName .. "_Config"))) then return end	-- Make sure config support exists

addon.configPanel = LOA:AddEntry(addonName, nil, addonName .. "_Config")

_G['SLASH_' .. addonName .. 1] = '/' .. addonName
_G['SLASH_' .. addonName .. 2] = '/' .. addonName:lower()
_G['SLASH_' .. addonName .. 3] = '/' .. addonName:upper()
SlashCmdList[addonName] = addon.configPanel

InterfaceOptionsFrame:SetFrameStrata('HIGH')
InterfaceOptionsFrame.SetFrameStrata = addon.DoNothing

local logo = CreateFrame('Frame', nil, InterfaceOptionsFrame)
logo:SetHeight(256)
logo:SetWidth(256)
logo:SetPoint('BOTTOM', InterfaceOptionsFrame, 'TOP', 0, -68)
logo:SetBackdrop({
	bgFile = [[Interface\AddOns\GrimUI\Media\GrimUILogo]],
	edgeFile = nil,
	edgeSize = 0,
	tile = false,
	insets = { left = 0, right = 0, top = 0, bottom = 0 }
})
logo:Hide()
addon.configPanel:SetScript('OnHide', function()
	InterfaceOptionsFrame:SetWidth(648)
	logo:Hide()
end)

addon.configPanel:SetScript('OnShow', function()
	InterfaceOptionsFrame:SetWidth(800)
	logo:Show()
end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
11-01-10, 04:24 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
and thinking about it lol that registerdefault is trivial since it has nothing to do with the new variable added. it effects a different variable that is called GrimUISettings shorted by addon.settings

its trivial. all the functions pertaining to the moveable frames list are in that first chunk of code.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » saving tables as variables in the saved variables


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