Originally Posted by gmarco
Thanks for the reply Phanx,
I opened this new post because I like to discuss about this a little bit more if possible....
Is there a reason to use a variable as NON LOCAL ?
For example ... another addon of mine: Aggromon uses some saved variables for the configuration option.
These are defined in the .toc file:
Lua Code:
## SavedVariables: AGGROMON_ACTIVE, AGGROMON_SOUND, AGGROMON_CHAT, AGGROMON_SHOW, AGGROMON_SNDFLE, AGGROMON_ENAPVP
and in the addon I have:
Lua Code:
local ADDON = ... -- defaults if not founds values AGGROMON_ACTIVE = AGGROMON_ACTIVE or true AGGROMON_SOUND = AGGROMON_SOUND or true AGGROMON_CHAT = AGGROMON_CHAT or false AGGROMON_SHOW = AGGROMON_SHOW or false AGGROMON_SNDFLE = AGGROMON_SNDFLE or 1 AGGROMON_ENAPVP = AGGROMON_ENAPVP or false -- etc etc ...
I used them as non local, but the names should be fine to not break any others things in the UI.
The question is :-)
Is it fine or I should define them as local even if I am exporting outside the addon ...
Thanks again to all of you.
P.s
Checking better I have also this one :-)
Lua Code:
SLASH_AGGROMON1 = "/aggromon"; SlashCmdList["AGGROMON"] = function() InterfaceOptionsFrame_OpenToCategory(options) end
|
Depends on your number of vars, and addon structure. If you have a lot of saved vars to work with, it's better to slap into the addon table, so you can reach them faster as self.randomsavedvar. You could also reduce that 6 globals into 1 if you store all the 6 variables in 1 global table, like AGGROMON[ACTIVE] etc.
Slash commands must be global, else the user won't be able to use them.