Thread Tools Display Modes
02/02/18, 06:06 PM   #1
zgwortz
Join Date: Jun 2015
Posts: 23
Reading Saved Variables across accounts

Hi all!

Some time ago I could have sworn I ran into an addon which had support for settings across multiple accounts (not just characters...). I even remember looking at the code briefly - it was doing something accessing the saved file data at a higher level (it was doing something interesting with ZO_SavedVars, I believe...) , but I cannot recall the details of how it got there or which addon was doing it, and now I'm interested in coding something which does the same.

I'm not sure if this other addon was accessing other account data as read/write or read only, but for my purposes, it would be acceptable if the other account data was read-only.

Does anyone have any idea which addon this might have been, or suggestions on how to accomplish this?
  Reply With Quote
02/02/18, 06:37 PM   #2
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
Check out the code here: https://github.com/esoui/esoui/blob/..._savedvars.lua

It's the source code for the saved variables.


It looks like you might be able to access it with ZO_SavedVars:New(savedVariableTable, version, namespace, defaults, profile, displayName, characterName, characterId, characterKeyType), by changing the displayName parameter.
  Reply With Quote
02/05/18, 10:35 AM   #3
zgwortz
Join Date: Jun 2015
Posts: 23
Thanks! After reading your reply, I did a bit of a deep dive into the ZOS code, and wrote a couple of Addons to test a number of things. I learned a LOT about how SavedVariables work, and am doing a few more tests -- I hope to put together a fairly detailed document soon on everything I learned. But for this specific question, the quick answer is this:

You *can* use ZO_SavedVars:New() as you described, but it only works if you already know the displayName of the account you want to view. Since, as far as I can tell, there's no way in the API to enumerate through the different accounts which have saved data on your machine (if anyone knows an API call for this, let me know...), we have to fall back to a different solution...

...which turns out to be trivial and very easy. Because once your addon is loaded, your savedVariablesTable is ALSO loaded as a global, if it exists. Thus, if your call is something like ZO_SavedVars:New("MyGreatAddon_SavedVariables", ...), you can simply check the global MyGreatAddon_SavedVariables directly -- all the accounts are keys under the top level "Default" key (or the profile if you are using as different profile...). You can access it directly or with _G["MyGreatAddon_SavedVariables"] if you want to do it that way.
  Reply With Quote
02/05/18, 12:17 PM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
Have you checked the wiki? It already contains several tutorials and documents that cover saved variables and even explain that data for different accounts is stored in the same table. Just saying.
  Reply With Quote
02/05/18, 01:32 PM   #5
zgwortz
Join Date: Jun 2015
Posts: 23
Actually, I'd checked out the wiki, read just about every post here about SavedVariables, done Google searches, and there's really nowhere I could find where it clearly states that the entire table, including multiple accounts, is available as a global. It was only when I read through the ZO_SavedVars:New() code that I saw that was the case.

This may be a case where addon developers who have been doing this a while are seeing this as such an obvious bit of knowledge they've never actually written it down anywhere. (Nor is it particularly important to know *unless* you are working ouside the box on something like cross-account settings...)

A lot of the experiments I did this weekend were driven by my curiosity about the side effects of that, and may be of interest to others. Sometimes it helps to have the "obvious" written down.
  Reply With Quote
02/05/18, 01:40 PM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
I don't know about the other tutorials, but at least mine contains this information (part 4).
The SavedVariables are simply global variables and it is up to us what we store in them. It is in most cases useful to create sub tables for display names, because multiple accounts can be used on the same PC and we do not want to mix their data up.
Not sure how I can make it any more clear than that?
  Reply With Quote
02/05/18, 02:59 PM   #7
zgwortz
Join Date: Jun 2015
Posts: 23
You're right, and I missed that page when searching the wiki. That said, even if I had read that paragraph, I'm not sure I would have connected it with the question I had above. As I mentioned before -- it's easy to forget that for some people this is isn't at all obvious. I can point to a whole bunch of SavedVariables questions on this forum which would have been more easily answered by simply saying "Oh, it's a global - just use that."

Nor would I have learned a lot of other interesting tidbits (and raised a lot more questions in my head) if I hadn't investigated further. Right now, for example, I'm looking at the corruption issues with too many entries in the file -- some very quirky behavior there.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Reading Saved Variables across accounts

Thread Tools
Display Modes

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