Scope of SavedVariables insruction
Hi !
The SavedVariables directive in an add-on's TOC-file specifies the variables it saves in-between gaming sessions. I've been developing an add-on for quite some time now, which is constructed in a very Java-like namespacing system, that is, all seperate components of the add-on are placed into different namespaces. This is accomplished by defining nested array/table variables and later-on defining the variables and functions as fields inside the table. However, when I try to specify a table variable defined inside a namespace as the variable to save, it fails to accomplish it. In order for SavedVariables to find and save te variable, I must define the table at global level, i.e. not inside any namespaces. While the current approach uses a global variable, that is then copied inside the namespace into the actual table when VARIABLES_LOADED event is triggered, I would certainly like to know what the scope of SavedVariables is, if anyone knows.. To me, it seems it can only identify global-level variables correctly.. - Gorak |
You're trying to save a property on an object without saving the entire object?
Just save the top-level object and all nested objects will be saved. If this is inefficient (for example too many transient state values will be saved) the normal solution is to separate the persistant state into an object and then save that. This object can have nested tables that mirror the nesting in other parts of your code. You can use Lua's meta-table feature to bind the persistant and transient objects together. You might also be trying to build a monolithic add-on. Do you really need extensive nesting? Can you refactor your code into several add-ons with a flatter namespace? |
You can only store global variables in SavedVariables.lua.
|
Quote:
Quote:
Quote:
- Gorak |
All times are GMT -6. The time now is 05:12 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI