Thread Tools Display Modes
03-12-11, 02:09 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Adding to a table and a variable based on version checking...

Okay so i have a frame mover system. Sometimes i find i need to add certain frames to the default and i need the ui to check when someone downloads an update if new frames were added to the default table and if so add them to the variables. Without wiping anything the user may have added in between versions. Can I somehow have it version check then if it finds that its a new version compare the default table to the current saved variables and then copy only the missing entry's?

This is the relevant part of the code. Note that the addon already stores the last version its accessed via addon.settings.version a tonumber will be required. Edit- i added the beginning of the function for it just dont know how to make the tables compare and then add to accordingly.

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()
	if not GMoveableFrames then
		GMoveableFrames = GMoveableFrames or {
			['MiniMapLFGFrame'] = false,
			['ShardBarFrame'] = false,
			['BNToastFrame'] = false,
			['SpellBookFrame'] = false,
			['QuestLogFrame'] = false,
			['FriendsFrame'] = false,
			['LFDParentFrame'] = 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,
			['ContainerFrame1'] = false,
			['ContainerFrame2'] = false,
			['ContainerFrame3'] = false,
			['ContainerFrame4'] = false,
			['ContainerFrame5'] = false,
			['Minimap'] = false,
			
			--GrimUI Frames
			['GrimUIPlayerFrame'] = false,
			['GrimUIPartyFrame1'] = false,
			['GrimUIPartyFrame2'] = false,
			['GrimUIPartyFrame3'] = false,
			['GrimUIPartyFrame4'] = false,
			['GrimExpBar'] = false,
			['GrimRepBar'] = false,
			['GDevBar'] = false,
			['GUITTAnchor'] = false,
		}
	end
end

--[[-----------------------------------------------------------------------------
Initialize
-------------------------------------------------------------------------------]]
local CurVerNum = tonumber(GetAddOnMetadata(addonName, 'Version'))
local LastVerNum

local function VerCheckUpdate()
	LastVerNum = tonumber(addon.settings.version)
	if CurVerNum > LastVerNum then 
		dosomthing
	end
end

local moveableframes = {}

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)
		addon:DefaultMoveableFrames()
		
		moveableframes = CopyTable(GMoveableFrames)

		for name, parent in pairs(moveableframes) do
			if HookFrame(name, parent) then
				moveableframes[name] = nil
			end
		end
		if next(moveableframes) then return end
		addon.UnregisterEvent(self, event)
	end

	addon.RegisterEvent("MoveFrames-Hook", 'ADDON_LOADED', HookFrames)
	HookFrames("MoveFrames-Hook", 'ADDON_LOADED')
end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 03-12-11 at 02:28 PM.
  Reply With Quote
03-12-11, 03:43 PM   #2
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Ive got the function lookin like this. i think its having issues passing the value part of the table in the tinsert part

edit - and this has issues with the tonumber it cant conver "4.0.6.06" to a number... it cant convert either string it returns nil for both tonumbers...

local function VerCheckUpdate()
LastVerNum = tonumber(addon.settings.version)
if CurVerNum > LastVerNum then
for gname, gparent in pairs(GMoveableFrames) do
local TabCont = tContains( DefGMoveableFrames, gname )
if TabCont == nil then
tinsert(GMoveableFrames, (gname + gparent))
end
end
end
end
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 03-12-11 at 03:53 PM.
  Reply With Quote
03-12-11, 03:59 PM   #3
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
local a, b, c, d = string.split("4.0.6.06")
-- a is now "4", b is "0", c is "6" and d is "06"

You can convert these 4 variables to numbers with tonumber(), but you can also do math (number coercion) such as

local version = a*10000 + b*1000 + c*100 + d

and compare the number.
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote
03-12-11, 05:27 PM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
got it
Code:
local function VerCheckUpdate()
	local CurVer = GetAddOnMetadata(addonName, 'Version')
	local LastVer = _G[addonName .. "Settings"].version
	
	if LastVer then
		if CurVer > LastVer then 
			for gname, gparent in pairs(DefGMoveableFrames) do 
				local TabCont = tContains( GMoveableFrames, gname )
				if TabCont == nil then
					GMoveableFrames[gname] = gparent
				end
			end
		end
	end
end
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
03-12-11, 10:43 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You could also do

local a, b, c, d = string.split("4.0.6.06")
local version = tonumber(a..b..c..d)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
03-14-11, 08:41 AM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
in the end i did not need the tonumber after all. turns out it was able to compare numerically the string "4.0.6.05" to a similar string with out tonumber.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Adding to a table and a variable based on version checking...

Thread Tools
Display Modes

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