Monday, May 10, 2010

How to persist data between sessions in your World of Warcraft Addon

After fiddling around with trying to save data between game sessions, I've laid out a few lines of code that could easily used in any sample addon you ever decide to develop. Assuming that you've already setup your hello world addon, you can simply add these lines to to your OnInitialize callback to create a new data store.

Now if you want to save data to it (or insert a row), do the following

If you want to read off of the data store, do the following

The reason why I put 'global' is because global signifies storing data for all characters between the account. As the developer, you have a choice of scoping:

  • 'profile'
  • 'char'
  • 'realm'
  • 'race'
  • 'faction'
  • 'class'
  • 'factionrealm'
  • 'global'
  • 'profiles'
Since the addon I'm developing stores data across all characters I set mine up for global data collection.