-
Notifications
You must be signed in to change notification settings - Fork 0
Iterating Over Characters and Accounts
LibSavedVars can manage saved data at multiple levels:
- Account-wide settings.
- Character-specific settings.
- Multiple characters within an account.
For advanced addon features, it may be useful to inspect or process saved data across characters or accounts.
Common use cases include:
- Creating account summaries.
- Migrating data between characters.
- Displaying character profiles.
- Synchronizing settings.
- Building management tools.
- Debugging saved variables.
ESO stores saved variables using a hierarchy based on the storage type.
A character-specific saved variable typically has a structure similar to:
MyAddonSavedVariables
{
["Default"] =
{
["@AccountName"] =
{
["Character One"] =
{
settings = {}
},
["Character Two"] =
{
settings = {}
}
}
}
}
An account-wide saved variable typically has:
MyAddonSavedVariables
{
["Default"] =
{
["settings"] = {}
}
}
The exact structure depends on the ESO saved variable API used and whether the addon uses account-wide or character settings.
Account-wide settings normally contain a single shared data set.
Example:
local accountSettings =
LibSavedVars:NewAccountWide(
"MyAddonSavedVariables",
1,
nil,
defaults
)Access the active account-wide settings:
local settings = accountSettingsFor normal addon operation, direct access is preferred:
settings.theme = "Dark"There is usually no need to iterate accounts because an account-wide saved variable represents the current player's account.
Character iteration is useful when an addon stores per-character data.
Example character data:
Account
|
+-- Character A
| level = 50
| class = "Dragonknight"
|
+-- Character B
level = 25
class = "Sorcerer"
An addon may want to process:
- All known characters.
- Character-specific profiles.
- Character history.
- Character settings.
Character and account iteration generally requires access to the underlying SavedVariables table.
Example:
local rawData = characterSettings:GetRawDataTable()The raw table contains only stored values.
It does not include values supplied from defaults.
A typical character iteration pattern:
local rawData =
characterSettings:GetRawDataTable()
for characterName, characterData in pairs(rawData) do
d(characterName)
-- Process characterData
endExample:
for characterName, data in pairs(rawData) do
local level = data.level
d(zo_strformat(
"<<1>> is level <<2>>",
characterName,
level
))
endWhen working with shared SavedVariables structures, an addon may encounter multiple account entries.
Example:
SavedVariables
|
+-- @AccountOne
| Character A
| Character B
|
+-- @AccountTwo
Character C
Iteration:
for accountName, accountData in pairs(savedVariables) do
d(accountName)
for characterName, characterData
in pairs(accountData) do
d(characterName)
end
endLSV_Data is designed primarily for managing the current user's active settings.
It provides:
- Active account-wide settings.
- Active character settings.
- Pinned account settings.
- A unified settings view.
Example:
local active =
data:GetActiveSavedVars()The returned table represents the current active configuration.
It is not intended to replace direct iteration over the underlying SavedVariables structure when inspecting every character.
For normal settings processing, use:
for key, value in data:GetIterator() do
d(key, value)
endThis returns the effective settings view, including:
- Character settings.
- Account-wide settings.
- Pinned account keys.
Example:
Active Settings
window
theme
combat
filters
A common use case is comparing character settings.
Example:
local characters = {
"Tank",
"Healer",
"Damage"
}
for _, character in ipairs(characters) do
local settings =
rawData[character]
-- Compare settings
endPossible uses:
- Copying profiles.
- Detecting differences.
- Displaying character summaries.
A migration or management tool may copy settings:
rawData["Character B"].theme =
rawData["Character A"].themeCare should be taken:
- Validate the source exists.
- Avoid overwriting user data unexpectedly.
- Use migrations when changing permanent data formats.
Migrations usually operate on one saved variable object at a time.
Example:
settings:Migrate(3, function(savedVars)
for key, value in pairs(savedVars) do
-- Convert old data
end
end)Avoid migrating every character manually unless the saved data format requires it.
Large addons may have:
- Many characters.
- Large history tables.
- Cached information.
When iterating:
- Avoid scanning all characters during frequent events.
- Perform large scans during initialization or user-requested actions.
- Cache results when appropriate.
- Avoid modifying tables while iterating.
When iterating characters and accounts:
- Use the normal LibSavedVars interface for current settings.
- Use raw data access for administrative operations.
- Do not assume every character has the same data.
- Handle missing settings gracefully.
- Avoid modifying saved data during simple inspection.
- Use migrations for permanent structural changes.
LibSavedVars provides two different approaches depending on the goal:
| Task | Recommended Method |
|---|---|
| Access current settings | settings.key |
| Iterate active settings | GetIterator() |
| Inspect stored values | GetRawDataTable() |
| Process all characters | Iterate raw character data |
| Manage current storage mode | LSV_Data |
Understanding the difference between the active settings view and the underlying SavedVariables structure is essential when building advanced account and character management features.