ESOUI

ESOUI (http://www.esoui.com/forums/index.php)
-   Lua/XML Help (http://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Can I access SavedVariables of other addon (http://www.esoui.com/forums/showthread.php?t=7578)

Haaxor1689 01/20/18 04:31 AM

Can I access SavedVariables of other addon
 
Hi, I would like to do an extension for someone else's addon and for that I would need to acces it's SavedVariables without modifying that addon. Is this possible? Thanks.

votan 01/20/18 04:57 AM

Quote:

Originally Posted by Haaxor1689 (Post 33666)
Hi, I would like to do an extension for someone else's addon and for that I would need to acces it's SavedVariables without modifying that addon. Is this possible? Thanks.

The answer is as most times in life: Yes, with a big but:
The saved variables are global, so yes you can, but:
1. You have to wait until the other addons are loaded. One way to do this is to make your addon
## OptionalDependsOn: in the manifest.txt.
2. Reading is ok, but for changing properties, you have check what the code does, which normally change them.

Haaxor1689 01/20/18 05:07 AM

Quote:

Originally Posted by votan (Post 33667)
The answer is as most times in life: Yes, with a big but:
The saved variables are global, so yes you can, but:
1. You have to wait until the other addons are loaded. One way to do this is to make your addon
## OptionalDependsOn: in the manifest.txt.
2. Reading is ok, but for changing properties, you have check what the code does, which normally change them.

Thanks for the reply. I only need to read those values and I already have those addons in `## DependsOn:`. I'm still getting null tho, how exactly should I load those values? Do I need to have the files I want to load in `## SavedVariables:`? Do I simply load them with `ZO_SavedVars:New`?

This is my almost first attempt at creating addon for eso and since the documentation is pretty lacking I'm not sure why it isn't working.

votan 01/20/18 05:42 AM

Quote:

Originally Posted by Haaxor1689 (Post 33668)
Thanks for the reply. I only need to read those values and I already have those addons in `## DependsOn:`. I'm still getting null tho, how exactly should I load those values? Do I need to have the files I want to load in `## SavedVariables:`? Do I simply load them with `ZO_SavedVars:New`?

This is my almost first attempt at creating addon for eso and since the documentation is pretty lacking I'm not sure why it isn't working.

You can have a look at http://www.esoui.com/downloads/info9...eTooltips.html. There I read the values from QuickEnchanter, if present.

Basically, due to DependsOn, the AddonLoaded callback is called for the other addon first. So once the addonName is the name of the other addon, you can use the SavedVar as if it would be yours.
You just have to use the same ZO_SavedVars method as the other addon, just without any defaults.

Haaxor1689 01/20/18 06:08 AM

Quote:

Originally Posted by votan (Post 33669)
You can have a look at http://www.esoui.com/downloads/info9...eTooltips.html. There I read the values from QuickEnchanter, if present.

Basically, due to DependsOn, the AddonLoaded callback is called for the other addon first. So once the addonName is the name of the other addon, you can use the SavedVar as if it would be yours.
You just have to use the same ZO_SavedVars method as the other addon, just without any defaults.

Thanks a lot. I forgot that those variables are global and when my addon initializes those dependencies are already initialized so I can just read the savedVariables from their global.

And for the rewriting of savedVariables, can I just use that reference (I assume that it's just a reference) to write to their savedVariables?

Baertram 01/20/18 06:12 AM

You maybe could use the global savedvars of the other addon. But you need to check if they are using acocunt wide or character saved avrs, using the charname as key (ZO_SavedVars:New) or the new method with the charId (ZO_SavedVars:NewCharacterId) which is rename save.

And messing around with other addon's savedvars won't work properly if the other addon changes them back upon reloadui somehow from it's internal savedvars.
The addon loads the savedvars into lest's say local settings 0 ZO_SavedVars:new(...).
You change the global vars now from your addon in this addon's savedvars.

Reloadui -> The adodnw rites it's local settings to the savedvars and overwrites your changed settings int he global SV again.

votan 01/20/18 06:32 AM

Quote:

Originally Posted by Baertram (Post 33673)
You maybe could use the global savedvars of the other addon. But you need to check if they are using acocunt wide or character saved avrs, using the charname as key (ZO_SavedVars:New) or the new method with the charId (ZO_SavedVars:NewCharacterId) which is rename save.

And messing around with other addon's savedvars won't work properly if the other addon changes them back upon reloadui somehow from it's internal savedvars.
The addon loads the savedvars into lest's say local settings 0 ZO_SavedVars:new(...).
You change the global vars now from your addon in this addon's savedvars.

Reloadui -> The adodnw rites it's local settings to the savedvars and overwrites your changed settings int he global SV again.

The ZO_SavedVars is a wrapper. Even if you have two wrapper within two addons, the common, global savedVariable is used.

Ayantir 01/20/18 11:39 AM

Please avoid if you didn't contacted the author, especially if you change the sv.

Lua Code:
  1. TheNameOfTheVarInMetaFile[GetDisplayName()]

after it's either ["Defaults$"] or charname or the char id depending on how the addon save the data.

sirinsidiator 01/20/18 02:22 PM

I agree with Ayantir. Just because it's possible doesn't mean it is a good idea.
Changing the save data of another addon can cause issues for both addons. When the original addon changes and something breaks due to you changing their data, either the author of it will get reports for some bug that has nothing to do with his addon or you will get reports because your addon won't work anymore.

Baertram 01/20/18 04:04 PM

Maybe contact the author so he provides a global function in his addon which you can use to update the data properly in both addons.


All times are GMT -6. The time now is 03:51 PM.

vBulletin © 2018, Jelsoft Enterprises Ltd
© 2014 - 2017 MMOUI