Originally Posted by Seerah
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
|
Right. That's how I'm currently doing it to prevent issues with globals, but that table is still a global. And other addons can still potentially mess things up. It's far less likely, but they still can.
Although the "local var = MyAddonTable.var" is not two-way. If you change the value of var, you still have to export it back out to MyAddonTable.var.