Thread Tools Display Modes
08-16-08, 07:06 PM   #1
Fireproof213
A Cyclonian
 
Fireproof213's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 43
I'm a bit confused with some tidbits of code, please help!

Alright, I'm trying to learn how to code addons real good, and I figured I'd try reading some addons that are simple yet good, so I chose OmniCC due to all the handy notes in the LUA file.

Well, within the first 3-5 lines of code (didn't bother counting) I saw this:

Code:
local CURRENT_VERSION = GetAddOnMetadata('OmniCC', 'Version') --the addon's current version
so I went searching for where the local variable is used, and found a strange bit of code that I'm confused about. Here it is:

Code:
function OmniCC:Enable()
	if not(OmniCCDB and OmniCCDB.version) then
		self:LoadDefaults()
	else
		local cMajor, cMinor = CURRENT_VERSION:match("(%d+)%.(%d+)")
		local major, minor = OmniCCDB.version:match("(%d+)%.(%d+)")

		if major ~= cMajor then
			self:LoadDefaults()
		elseif minor ~= cMinor then
			self:UpdateSettings()
		end

		if OmniCCDB.version ~= CURRENT_VERSION then
			self:UpdateVersion()
		end
	end

what exactly is this function doing with the version?
  Reply With Quote
08-16-08, 07:19 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
It's most likely in there from when Tuller rewrote OmniCC, changed around options/settings, etc. Basically how the addon worked. As that part of the code checks for the addons major and minor revision number and compares it to a specific version. You'll also see some addons deal with version numbers in their code to have it display in config menus, chat/slash commands, and error reporting mods such as BugGrabber.
__________________
"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
08-16-08, 07:22 PM   #3
Fireproof213
A Cyclonian
 
Fireproof213's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 43
Originally Posted by Seerah View Post
It's most likely in there from when Tuller rewrote OmniCC, changed around options/settings, etc. Basically how the addon worked. As that part of the code checks for the addons major and minor revision number and compares it to a specific version. You'll also see some addons deal with version numbers in their code to have it display in config menus, chat/slash commands, and error reporting mods such as BugGrabber.
thanks loads, do you have any recommendations for a new addon programmer to read the code of to pick up some knowledge?
  Reply With Quote
08-16-08, 07:37 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
If you don't have it yet, get the WoW Programming book. I also suggest checking out these websites: http://www.lua.org/pil/ and http://lua-users.org/wiki/TutorialDirectory

As for addons, it all depends on what you want to do. But pick something simple that doesn't require any libraries - that way all code will be in one place.
__________________
"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
08-16-08, 10:15 PM   #5
VincentSDSH
Non-Canadian Luzer!
 
VincentSDSH's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 350
Originally Posted by Fireproof213 View Post
thanks loads, do you have any recommendations for a new addon programmer to read the code of to pick up some knowledge?
For the love of God and Country don't be afraid to a) ask the author, b) ask someone else, or c) look foolish.

Far too many people hack code together rather than commit C. Truth is, decent developers will go out of their way to not make you feel stupid or foolish if you are earnestly trying to learn something and wind up asking a silly question: it builds a better author community, safer/better mods for the community, generally they're returning the favor for others helping them, the more you know the more you can help others and give them a break , and in general they're in touch with the beauty and poetry of "Good Code" just for it's own sake. (But beware asking b/c you're too lazy to try it yourself: that's a good way to quickly shut a lot of doors)

You can also figure a lot of things out by seeing how Blizzard did it with it's xml/lua by trolling http://wowcompares.com.

By far, the best thing I've found is to look at different mods that solve similar problems and see the different approaches and what is similar. You sometimes wind up spending a lot of time in the LUA language reference when you're just starting out but it's a good technique to help you see the forest among the trees, and it helps you determine what is/isn't "overly complex code" that might solve a problem your mod won't ever have.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » I'm a bit confused with some tidbits of code, please help!


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