ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   AddOn Help/Support (https://www.esoui.com/forums/forumdisplay.php?f=164)
-   -   adding new saved variables (https://www.esoui.com/forums/showthread.php?t=2476)

Argusus 11/28/14 02:10 PM

adding new saved variables
 
Is there a way to add a new "default" saved var to my existing variables without having to change the version number and clear out current user's saved var file?

is it easy as just adding the new value to my code on addon load?

Code:

MYADDON.savedVariables.AutoSaveChanges = 0

Garkin 11/28/14 09:42 PM

Yes, it is exactly that easy as you say.

Just add some flag to the saved variables, so you can check if variables are updated already. Something like:

Lua Code:
  1. local newDefaults = {
  2.     internalVersion = 1,
  3.     key1 = value1,
  4.     ...
  5. }
  6.  
  7. MYADDON.savedVariables = ZO_SavedVars:New(...) --here should be correct arguments to the function
  8.  
  9. local currentVersion = MYADDON.savedVariables.internalVersion or 0
  10.  
  11. if currentVersion < newDefaults.internalVersion then
  12.     for k, v in pairs(newDefaults) do
  13.         MYADDON.savedVariables[k] = v
  14.     end
  15. end

Argusus 11/29/14 01:10 AM

Quote:

Originally Posted by Garkin (Post 13522)
Yes, it is exactly that easy as you say.

Just add some flag to the saved variables, so you can check if variables are updated already. Something like:

Lua Code:
  1. local newDefaults = {
  2.     internalVersion = 1,
  3.     key1 = value1,
  4.     ...
  5. }
  6.  
  7. MYADDON.savedVariables = ZO_SavedVars:New(...) --here should be correct arguments to the function
  8.  
  9. local currentVersion = MYADDON.savedVariables.internalVersion or 0
  10.  
  11. if currentVersion < newDefaults.internalVersion then
  12.     for k, v in pairs(newDefaults) do
  13.         MYADDON.savedVariables[k] = v
  14.     end
  15. end

thank you very much


All times are GMT -6. The time now is 04:42 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI