Originally Posted by Xrystal
I believe the first var1 is classed as global across all addons and is the same as adding it to the _G table.
|
Correct.
Originally Posted by Xrystal
I am not sure if ESO has the equivalent of the addon wide data table but that would be the only way to be addon wide across all files for just a single addon.
|
No, it does not.
Local variables are available at the scope they are defined and lower. Global variables are available to all things - hence being called "global". If you use a global variable called
spacer, and I accidentally leak a global variable also called
spacer, whichever one was defined last will overwrite the other.
If you want variables accessible throughout your entire addon, across multiple files, then use a table to store them in. Here is just one example of how you can do that.
File1.lua
Lua Code:
MyAddonTable = {} --define your table
local MyAddonTable = MyAddonTable --go ahead and give it a local reference, too, for this file
MyAddonTable.var = "varForAllFiles"
File2.lua
Lua Code:
--since File1 loaded first, MyAddonTable has already been created
local var = MyAddonTable.var --we can copy the value of MyAddonTable.var to a local variable