One more question about ZO_SavedVars
When I searched the API for information about ZO_SavedVars I could not find a way to load the variables after the first load. Is there a way to update stored variables more than once, or does this update only happen once?
I've tried doing: Quote:
|
SavedVariables via ZO_SavedVars will be assigned to your table.
If you update any value in your table they will be written to the file on zone change, logout, quit. So you need to assign the SavedVariables in your addon's EVENT_ADD_ON_LOADED callback function e.g. and then just update the table you have assigned to the ZO_SavedVars. EVENT_ADD_ON_LOADED will be called for EACH addon so make sure you will check the event's parameter addonName if it's "your addon" and only then do your addon related stuff AND unregister the EVENT_ADD_ON_LOADED again so it will not fire again afterwards. Eacht ime you do a reloadui etc. the event will be registerted again and load your addon code again, so this way your SavedVariables will be read from the disk files to your ingame table again. Be sure to also add the name you have chosen for your SavedVariables in your addon's manifest txt file as well after the ##SavedVariables: tag! AND do not choose the same name for your global addon variable and the SavedVariables name as the SavedVariables name will create a global table with that name as well. In your example this would be something like this: Lua Code:
In your addon's txt file add: ## SavedVariables: SavedVars But I'd choose something else then just SavedVars! Add your addon name up in front like MyAddon_SavedVars so it is unique! Else other addons might overwrite it. Read this tutorial for further information: https://wiki.esoui.com/SimpleNotebookTutorial/part1 Part4 contains savedVariables: https://wiki.esoui.com/SimpleNotebookTutorial/part4 There also exist basic addon examples where you can spy the code: https://www.esoui.com/downloads/info...late.html#info |
Quote:
Quote:
Can i update saved variables every time when i need to check file? Or i can do it another way? Thanks! |
Did you add the name of your SavedVariables to your txt file like I have described?
## SavedVariables: TTCPSavedVars Else the global table _G["TTCPSavedVars"] won't be created and nothing will be saved upon logout/reloadui/zone change loading screens. TTCP.CheckTable() needs to be called ONCE ONLY in your function TTCP:Initialize(). Else you will overwrite it always on each combat state change again with NIL and the default values from TTCP.Table! Just use TTCP.Saved after loading the savedvariables ONCE to access/change your SV data. And you should add an unregister to EVENT_ADD_ON_LOADED once your addon was loaded as after that the function shouldn't be called aymore. Remeber: It will be called once for EACH addon/library! Code:
TTCP = {} SavedVariables are a global table defined with your SV name "TTCPSavedVars", saved in the global table _G. As you put the name into your addon's txt file ## SavedVariables: tag it will create that table in _G -> _G["TTCPSavedVars"] (same as just TTCPSavedVars). You are able to access that table now ingame with your addon already, even without using ZO_SavedVars. As you use ZO_SavedVars:New... it will create a reference to that global table, adding some subtables and values like the version, accountName/characterId etc. depending on what you use as ZO_SavedVars:New... (AccountWide, CharacterIdSettings). And you assign this reference to your addons table TTCP.Saved now as a new reference. So TTCP.Saved -> points to TTCPSavedVars. And each time a reloadui/logout/zone change happens ZO_SavedVars transfers the data from TTCPSavedVars to your file live/SavedVariables/TTCP.lua |
Quote:
Code:
## Title: TTCP Quote:
Quote:
Or, maybe, i can read file using file : open(file)? In this way how to use absolute path in LUA? |
READ what I wrote at "Explanation" in my last post.
There is no manual file read or write in ESO! It ONLY happens at loading screens, login, logout, reloadui. Not as you call a function. All you need to do is update the table and it will be automatically written/read to/from your SV file upon loading screen/reloadui/logout. That's all. Access to files via lua in ESO is forbidden. https://wiki.esoui.com/Storing_data_and_accessing_files |
Quote:
|
All times are GMT -6. The time now is 02:58 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI