Thread Tools Display Modes
03-25-07, 03:29 PM   #1
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
GetAddOnMetadata function

Okay, so I'm writing my first addon - thought I'd start simple, since I'm learning pretty much everything as I go. All it will do is pop up a frame when a new version of that addon is installed. I made my frame in WoWUIDesigner, wrote out my lua page, and thought I'd store the version number in saved variables. Then, if the new version number is > than the saved version number, the frame would pop up with the major changes in my UI comp - things that users might need to do, like reset databases, etc. Because, let's face it, not everyone reads changelogs. (There would be an option to disable, of course.)

So... I found this function on WoWWiki - GetAddOnMetadata("addon", "field"), but I'm having difficulties in putting it into practice. Any help would be greatly appreciated.

Here is my lua:

Code:
--variables
SSWELCOME_LASTVERSION = 0
SSWELCOME_VERSION = 0;

function SSWelcome_OnLoad(self)
    self:RegisterEvent("ADDON_LOADED");
    self:RegisterEvent("PLAYER_ENTERING_WORLD");	
end

function SSWelcome_OnEvent(self, event, ...)
    if ( event == "ADDON_LOADED" ) then
		local addon = select(1, ...);
		if ( addon == "SSWelcome" ) then
			DEFAULT_CHAT_FRAME:AddMessage("Welcome to Seerah's Suitcase!");
		end
		return;
	end
    --current version?
	if ( event == "PLAYER_ENTERING_WORLD" ) then
		SSWELCOME_VERSION = GetAddOnMetadata("SSWelcome", "Version");
        return;
    end
    --updated?
    local version = GetAddOnMetadata("SSWelcome", "Version");
	if ( version > SSWELCOME_LASTVERSION ) then
            self.frame:Show()
        else self.frame:Hide()
    end
    --update sv
        SSWELCOME_LASTVERSION = version
end
and this is what gets put into my saved variables file....

Code:
SSWelcome = nil
__________________
"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

WoWInterface » Developer Discussions » Lua/XML Help » GetAddOnMetadata function


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