View Single Post
10/25/20, 09:28 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
SavedVariables via ZO_SavedVars will be assigned to your table.
If you update any value in your table they will be written to the file on zone change, logout, quit.

So you need to assign the SavedVariables in your addon's
EVENT_ADD_ON_LOADED
callback function e.g. and then just update the table you have assigned to the ZO_SavedVars.
EVENT_ADD_ON_LOADED will be called for EACH addon so make sure you will check the event's parameter addonName if it's "your addon" and only then do your addon related stuff AND unregister the EVENT_ADD_ON_LOADED again so it will not fire again afterwards.
Eacht ime you do a reloadui etc. the event will be registerted again and load your addon code again, so this way your SavedVariables will be read from the disk files to your ingame table again.

Be sure to also add the name you have chosen for your SavedVariables in your addon's manifest txt file as well after the
##SavedVariables:
tag!

AND do not choose the same name for your global addon variable and the SavedVariables name as the SavedVariables name will create a global table with that name as well.

In your example this would be something like this:
Lua Code:
  1. local defaultTable = {
  2.  myVarInSavedVariables = 1
  3. }
  4. local mySavedVariables = ZO_SavedVars:NewAccountWide("SavedVars", 1, nil, defaultTable)
  5.   --Change a value in the SavedVariables
  6.  myVarInSavedVariables.myVarInSavedVariables = 2

In your addon's txt file add:
## SavedVariables: SavedVars

But I'd choose something else then just SavedVars! Add your addon name up in front like MyAddon_SavedVars so it is unique! Else other addons might overwrite it.

Read this tutorial for further information:
https://wiki.esoui.com/SimpleNotebookTutorial/part1

Part4 contains savedVariables:
https://wiki.esoui.com/SimpleNotebookTutorial/part4

There also exist basic addon examples where you can spy the code:
https://www.esoui.com/downloads/info...late.html#info

Last edited by Baertram : 10/25/20 at 09:32 AM.
  Reply With Quote