Thread Tools Display Modes
11/24/15, 07:34 PM   #1
cyxui
AddOn Author - Click to view addons
Join Date: Nov 2015
Posts: 62
upgrade saved variable

I wonder if it is possible to upgrade saved variable. For example I had a version 1 savedvar, then later I decide to make some changes and the newer one is version 2. I want to be able to retrieve the version 1 var, update it and save it as version 2. In the above scenario if I call ZO_SavedVars:NewAccountWide with version = 2 directly it will wipe the version 1 var. If I call ZO_SavedVars:NewAccountWide with version = 1 then the version 2 vars will be wiped. Any one got a good way to solve this?
  Reply With Quote
11/24/15, 07:52 PM   #2
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
People generally forsake the versioning of saved variables and simply use the same version number forever.

I actually drafted some *migrations* for saved variables but then figured it wouldn't have appeal. =/
  Reply With Quote
11/25/15, 05:06 AM   #3
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,579
I don't use ZO_SavedVars in my addons and instead have my own structure. It's nothing special, but it allows me to upgrade my saved vars whenever I need. You might want to take a look at AwesomeGuildStore's Settings.lua.
  Reply With Quote
11/25/15, 05:32 AM   #4
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
in your metafile you have

Lua Code:
  1. ## SavedVariables: SOMETHING

in your lua, you have

Lua Code:
  1. db = ZO_SavedVars:New("SOMETHING", 2, nil, defaults, nil) -- 2 is for "version 2 here"

if you want to check v1 of your SV, just play with :

Lua Code:
  1. SOMETHING.Default[GetDisplayName()]
  Reply With Quote
11/25/15, 07:58 AM   #5
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
Originally Posted by Ayantir View Post
in your metafile you have

Lua Code:
  1. ## SavedVariables: SOMETHING

in your lua, you have

Lua Code:
  1. db = ZO_SavedVars:New("SOMETHING", 2, nil, defaults, nil) -- 2 is for "version 2 here"

if you want to check v1 of your SV, just play with :

Lua Code:
  1. SOMETHING.Default[GetDisplayName()]
Ayantir correct if I'm wrong but I think that if you initialized a SavedVars with same name but different version then your previous data was wiped, as in:

Lua Code:
  1. ZO_SavedVars:New("SOMETHING", 1, nil, {x = 1})
  2. ZO_SavedVars:New("SOMETHING", 2, nil, {}) --> version 1 is no more
  3. SOMETHING.Default[GetDisplayName()]["x"] == nil --> true
  Reply With Quote
11/25/15, 08:48 AM   #6
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by haggen View Post
Ayantir correct if I'm wrong but I think that if you initialized a SavedVars with same name but different version then your previous data was wiped, as in:

Lua Code:
  1. ZO_SavedVars:New("SOMETHING", 1, nil, {x = 1})
  2. ZO_SavedVars:New("SOMETHING", 2, nil, {}) --> version 1 is no more
  3. SOMETHING.Default[GetDisplayName()]["x"] == nil --> true
Ayantir is talking about doing it before using the helper class.
Lua Code:
  1. local olddata = SOMETHING.Default[GetDisplayName()]
  2. -- Check for old data and migrate
  3. ZO_SavedVars:New("SOMETHING", 2, nil, {}) --> version 1 is no more
  4. -- save migrated data, if exists
Which means, you have to know how the helper works.

The problem is within the helper, which saves the given version as the current version. No matter, if there is a higher version.
As soon as you query for version 1, version 2 will become version 1.

Last edited by votan : 11/25/15 at 09:19 AM.
  Reply With Quote
11/25/15, 09:34 AM   #7
Wandamey
Guest
Posts: n/a
I tried what I suggested on ESO forums and it seems to work.
If you find an elegant way to get rid of the first one after the second is populated it should do it.

a bit more detailled maybe :

Manifest
## SavedVariables: MyTestsVars MyTestsVars2
Code:
MyTests.Truc = ZO_SavedVars:NewAccountWide("MyTestsVars", 1, nil, {myolddata})
MyTests.Toto = ZO_SavedVars:NewAccountWide("MyTestsVars2", 1, nil, {})

testwhichoneisempty()
rebuildnewtable()
deleteuseless()
not the cleanest as you may be stuck with the 2 names in the manifest but can be safer if you collected data through time and can't afford a wipe.
  Reply With Quote
11/25/15, 10:02 AM   #8
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
It's unlikely you'll want to completely change everything in the saved table, so better keep ZO_SavedVars version unchanged, and either manage your own internal version like AGS, or upgrade vars individually:
Lua Code:
  1. if sv.oldVar ~= nil then -- needs upgrade
  2.     sv.newVar = convertOldData(sv.oldVar)
  3.     sv.oldVar = nil
  4. end
  Reply With Quote
11/25/15, 10:21 AM   #9
Wandamey
Guest
Posts: n/a
well that too...
like haggen and merlight said you don't have to change the version of the saved variables when you update your addon.
but i was under the impression you knew this already and had different needs. Maybe a bit more details on what you're up to ?

btw if you need to generate different files for your versions you may want to look at how Master Merchant does
I suppose he creates fake addons with just a save vars then he probably make their content global to use them in the main addon. Never used MM can't tell for sure. But if it is to extract data for your site, can be something to check too.

Last edited by Wandamey : 11/25/15 at 10:33 AM.
  Reply With Quote
11/25/15, 09:02 PM   #10
cyxui
AddOn Author - Click to view addons
Join Date: Nov 2015
Posts: 62
thanks for all the ideas guys
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » upgrade saved variable


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off