View Single Post
03/24/14, 04:00 PM   #10
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
Originally Posted by Seerah View Post
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:
  1. MyAddonTable = {}   --define your table
  2. local MyAddonTable = MyAddonTable   --go ahead and give it a local reference, too, for this file
  3. MyAddonTable.var = "varForAllFiles"

File2.lua
Lua Code:
  1. --since File1 loaded first, MyAddonTable has already been created
  2. 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.
  Reply With Quote