Thread: Global vars ?
View Single Post
10-30-14, 05:03 PM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by gmarco View Post
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:
  1. ## SavedVariables: AGGROMON_ACTIVE, AGGROMON_SOUND, AGGROMON_CHAT, AGGROMON_SHOW, AGGROMON_SNDFLE, AGGROMON_ENAPVP

and in the addon I have:

Lua Code:
  1. local ADDON = ...
  2.  
  3. -- defaults if not founds values
  4. AGGROMON_ACTIVE = AGGROMON_ACTIVE or true
  5. AGGROMON_SOUND = AGGROMON_SOUND or true
  6. AGGROMON_CHAT = AGGROMON_CHAT or false
  7. AGGROMON_SHOW = AGGROMON_SHOW or false
  8. AGGROMON_SNDFLE = AGGROMON_SNDFLE or 1
  9. AGGROMON_ENAPVP = AGGROMON_ENAPVP or false
  10.  
  11. -- 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:
  1. SLASH_AGGROMON1 = "/aggromon";
  2. SlashCmdList["AGGROMON"] = function()
  3.     InterfaceOptionsFrame_OpenToCategory(options)
  4. 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.
  Reply With Quote