-
Notifications
You must be signed in to change notification settings - Fork 0
Pinned Account Settings
When an addon supports both account-wide and character-specific settings, some settings may need to remain shared regardless of the active storage mode.
For example, a user may want:
- Window positions shared across all characters.
- UI themes shared across all characters.
- Character-specific gameplay preferences.
- Character-specific filters or configurations.
LibSavedVars supports this through pinned account settings.
Pinned settings allow selected keys to always use account-wide storage while the remaining settings follow the currently active storage mode.
Without pinned settings, an addon typically has to choose one storage model:
Account-wide:
Everything is shared.
or
Character:
Everything is independent.
Many addons need a mixed approach:
Account-wide:
window position
theme
color settings
Character:
build configuration
filters
preferences
Pinned account settings allow both behaviors at the same time.
When character settings are active, LSV_Data normally reads and writes values from the character saved variables.
Pinned keys are the exception.
Example:
settings:AddAccountWideToggle("window")
settings:AddAccountWideToggle("theme")With character settings active:
settings.window.x = 200
settings.theme = "Dark"
settings.build = "Tank"The data is stored as:
Account-wide
{
window = {
x = 200
},
theme = "Dark"
}
Character
{
build = "Tank"
}
The addon continues using one settings object.
Pinned settings are added through LSV_Data.
Example:
local settings = LibSavedVars:NewData(
accountSettings,
characterSettings
)
settings:AddAccountWideToggle("window")
settings:AddAccountWideToggle("theme")The specified keys are now always read from the account-wide saved variables.
A pinned setting can be removed by removing the key from the pinned configuration.
After removal, the setting follows the active storage mode again.
Example:
Before:
theme → Account-wide
After removing the pin:
theme → Active storage mode
Pinned settings can represent entire sections of data.
Example:
local defaults = {
ui = {
window = {
x = 100,
y = 100,
},
theme = "Dark",
},
combat = {
autoAttack = true,
},
}Pin the UI section:
settings:AddAccountWideToggle("ui")Result:
Account-wide
{
ui = {
window = {
x = 100,
y = 100
},
theme = "Dark"
}
}
Character
{
combat = {
autoAttack = true
}
}
All UI settings remain shared while combat settings remain character-specific.
Pinned settings are accessed normally.
The addon does not need special handling:
settings.ui.theme = "Light"
settings.combat.autoAttack = falseLibSavedVars determines where each value belongs.
Pinned settings remain account-wide regardless of the active storage mode.
Example:
settings:SetAccountSavedVarsActive(false)Now character settings are active.
The effective storage becomes:
Account-wide:
pinned settings
Character:
all other settings
Switching back:
settings:SetAccountSavedVarsActive(true)returns to:
Account-wide:
all settings
Good candidates for pinned settings:
- Window locations.
- UI layout.
- Theme selections.
- Color preferences.
- Global display options.
- Account-wide unlocks.
Poor candidates:
- Character builds.
- Character progress.
- Per-character filters.
- Character notes.
- Character-specific preferences.
A setting should be pinned only when users would reasonably expect the value to be shared.
When adding pinned settings to an existing addon, existing data may need to be moved.
Example:
Before:
Character Settings
{
theme = "Dark"
}
After:
Account Settings
{
theme = "Dark"
}
A migration should copy the existing value into the new location.
Example:
settings:Migrate(2, function(savedVars)
-- Move theme into account-wide storage
end)Migration helpers can simplify these operations.
When using pinned account settings:
- Pin complete logical groups when possible.
- Avoid pinning individual keys unnecessarily.
- Document which settings are shared.
- Test switching between storage modes.
- Test existing users upgrading to the new structure.
- Use migrations when changing where data is stored.
Pinned account settings allow an addon to combine the advantages of account-wide and character-specific storage.
They provide:
- Shared settings where appropriate.
- Character customization where needed.
- A single interface for addon code.
- Automatic handling of storage locations.
For addons that support flexible configuration, pinned settings provide a clean way to give users control without complicating addon development.