Go to Page... |
|
Thread Tools | Display Modes |
08/03/16, 08:35 AM | #1 |
SavedVariables, ZO_SavedVars, AccountWide, per character and name changes
Hello,
A little tutorial and things to known on savedvars. First, what is savedvars ? A savedVariable is a Lua variable which is dumped into a text file. A savedVariable MUST be a table. Elements in the table can be number, string, boolean, or table. Functions cannot be dumped, nil values are stripped. Why using savedvariables ? As long as we cannot save almost nothing on TESO DB on the server, the settings or other data which should persists must be stored somewhere, so here are the SavedVars. Where are they ? There are in Elder Scrolls Online\{environnement}\SavedVariables. Basically, it's Documents\Elder Scrolls Online\live(eu)\SavedVariables More info is on the Wiki : http://wiki.esoui.com/UserFolder Which file and what name ? The file have the name of your Addon metafile If your metafile is Something.txt, the Savedvariable file wille be Something.lua How can I enable a variable to be saved ? You can add this to the metafile Code:
## SavedVariables: var1 var2 var3 var4 var5 I want my settings have a default value, be set by character, or accunt wide ZOS give us an object to play more easily with saved vars. Please note this is totally optionnal. If in your code you do Lua Code:
But if you need some help to manage your SV, you should use the ZO_SavedVars object. How ? 1) your defaults array. it will contain the defaults values. If an user don't have SV, the whole content will be sent as "template". If you just added one subvariable, the new one will be pushed in and the existing ones won't be changed. Lua Code:
A first try will be : Lua Code:
This code will "link" the local db variable to the Savedvariable THE_NAME_OF_THE_VAR_IN_METAFILE. If a value doesn't exist in THE_NAME_OF_THE_VAR_IN_METAFILE, the constructor will fetch it from the defaults variable. please note if db and default should remain "local", THE_NAME_OF_THE_VAR_IN_METAFILE is leaked to _G (you can inspect it). changing db will change THE_NAME_OF_THE_VAR_IN_METAFILE. Methods
SavedVars versioning the 2nd parameter, version is a key (string or number) to push the defaults array even if an old value existed before. It erase old data. Avoid if possible changing version. You should only change version when there is an absolute need. (addon rewrited entirely, api bump). This action lead to reset all user config. Ex : Before : Lua Code:
After : Lua Code:
Limitations 32bits client has the inherent limitations of the 32Bits allocation memory.
Both 32 & 64 bits : Max length of string variable : 1000 characters. if your string variable is more than 1000 bytes, it won't be saved When is the file written ? The fle is written when the UI Reloads. Lua ReloadUI() Lua SetCVar() -- ONLY if it trigger a reload UI (a loading screen). Lua LogOut() Lua Quit() Windows Alt+F4 Clicking on the red X of the ESO window When Game kicks you on the loading screen Killing Process -> DATA NOT SAVED CRASH -> DATA NOT SAVED Bugs Having multiple Vars set in a same metafile is dangerous. If you want to have multiple SV please never do assignment between the variables (no var1 = var2 or any subkey of any variables) With Code:
## SavedVariables: var1 var2 Lua Code:
var2 will be nil in SV. (var1.key2 steal the value). If you want to do this, consider a table which embed both tables. Recursivity, 4GB file and crashs As in a lot of languages, Lua accept recursive calls, but if you try to save a var which contain a recursive call, it will crash your game. For this, you must :
If you play with ZOS datalists, you may consider the dataEntry recursive call. here are 2 screenshots of var which shouldn't be saved in SV. Last edited by Ayantir : 12/10/16 at 08:42 PM. |
|
ESOUI » Developer Discussions » Tutorials & Other Helpful Info » SavedVariables, ZO_SavedVars, AccountWide, per character and name changes |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Switch to Hybrid Mode |
Threaded Mode |
|
|