View Single Post
09-08-08, 02:44 PM   #29
Mikord
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 61
Originally Posted by Kerrang
Surely, the first time a user runs that addon, they will get an error because MyModSV isn't declared as a global variable - only within a local function???
Wrong. It will work just fine because it checks that it doesn't exist, and if it doesn't, it creates it. Variables (and functions) in lua are automatically global if they aren't specifically defined to be local.

Pay attention to the fact that the OnBagUpdate will NEVER be called prior to the loading or initialization of the SV because it's not registered until AFTER they are already loaded or initialized.

What I posted is fully functional as is. Try it out. Open your bags and move something. You'll get a message.

MyMod.toc
Code:
## Interface: 20400
## SavedVariables: MyModSV
MyMod.lua
MyMod.lua
Use all the code I posted earlier in post #23.

Last edited by Mikord : 09-08-08 at 02:57 PM.
  Reply With Quote