Skip to content

Supporting Both Character and Account‐Wide Settings

Shadowfen edited this page Jul 29, 2026 · 1 revision

Many addons begin with a single storage model: either account-wide settings or character-specific settings. As an addon grows, users may request more flexibility:

  • "I want my UI layout shared across all characters."
  • "I want my crafting settings different for each character."
  • "I want some settings shared and others customized."

LibSavedVars supports this scenario by allowing an addon to manage both account-wide and character-specific settings at the same time.

The LSV_Data class provides a unified interface that allows your addon to work with the active settings without needing to know where individual values are stored.

Why Support Both?

Different types of settings naturally belong in different places.

Account-wide Settings

Good candidates include:

  • Window positions.
  • UI themes.
  • Global addon preferences.
  • Color schemes.
  • Feature unlocks.

Example:

accountSettings.window.x = 250
accountSettings.theme = "Dark"

Every character sees the same values.


Character Settings

Good candidates include:

  • Character-specific builds.
  • Crafting preferences.
  • Combat configurations.
  • Character notes.
  • Per-character filters.

Example:

characterSettings.build = "Tank"

Only the current character sees the change.


Creating Both Saved Variables

Create separate saved variables objects for each storage model.

local defaults = {
    enabled = true,
    scale = 1.0,

    window = {
        x = 100,
        y = 100,
    },

    build = "",
}

Create the account-wide settings:

local accountSettings = LibSavedVars:NewAccountWide(
    "MyAddonSavedVariables",
    1,
    nil,
    defaults
)

Create the character settings:

local characterSettings = LibSavedVars:NewCharacterSettings(
    "MyAddonSavedVariables",
    1,
    nil,
    defaults
)

At this point, the addon has two independent storage locations.


Creating an LSV_Data Object

LSV_Data combines the two settings objects into a single interface.

local settings = LibSavedVars:NewData(
    accountSettings,
    characterSettings
)

The addon now interacts with settings rather than directly accessing either saved variable table.


Selecting the Active Storage Mode

The addon can determine which storage model is currently active.

Account-wide:

settings:SetAccountSavedVarsActive(true)

Character-specific:

settings:SetAccountSavedVarsActive(false)

Retrieve the currently active settings:

local activeSettings = settings:GetActiveSavedVars()

The returned table represents the storage model selected by the user.


Allowing Users to Switch Modes

Many addons provide an option such as:

Storage Mode:
( ) Account-wide
( ) Character-specific

When the user changes the option:

settings:SetAccountSavedVarsActive(useAccountWide)

The addon immediately begins using the selected storage location.

The rest of the addon does not need to change.

Instead of:

if accountMode then
    accountSettings.scale = 1.2
else
    characterSettings.scale = 1.2
end

use:

settings.scale = 1.2

LSV_Data handles the correct destination.


Mixing Account and Character Settings

Sometimes users want both:

  • Most settings character-specific.
  • A few important settings shared.

For example:

Account-wide:
    window position
    theme

Character:
    combat settings
    filters
    preferences

LibSavedVars supports this through pinned account settings.

settings:AddAccountWideToggle("window")
settings:AddAccountWideToggle("theme")

Now:

settings.window.x = 300
settings.theme = "Dark"
settings.build = "Healer"

stores:

Account-wide:
    window
    theme

Character:
    build

The addon uses one table while LibSavedVars manages the storage separation.


Migrating Existing Addons

Supporting both storage models is especially useful when changing an existing addon.

Example:

Version 1:

Account-wide:
    all settings

Version 2:

Account-wide:
    UI settings

Character:
    gameplay settings

A migration can:

  1. Read the existing account-wide data.
  2. Copy selected values to character storage.
  3. Enable the new storage model.

Users keep their existing configuration without manually re-entering settings.


Recommended Design Pattern

For addons supporting both storage models:

  1. Define a complete defaults table.
  2. Create account-wide and character saved variables.
  3. Create an LSV_Data object.
  4. Let users select their preferred storage model.
  5. Pin settings that should always remain shared.
  6. Access settings only through the LSV_Data interface.

Example:

local settings = LibSavedVars:NewData(
    accountSettings,
    characterSettings
)

settings:AddAccountWideToggle("window")
settings:AddAccountWideToggle("theme")

local active = settings:GetActiveSavedVars()

active.enabled = true

Summary

Supporting both account-wide and character-specific settings gives users greater control over how their addon configuration is stored.

LSV_Data removes the complexity of managing multiple storage locations by providing a single interface for:

  • Account-wide settings.
  • Character-specific settings.
  • Mixed storage through pinned keys.
  • Switching storage modes.
  • Migrating between storage models.

For simple addons, a single storage model is usually enough. For addons with many settings or a diverse user base, supporting both models provides a more flexible and user-friendly experience.

Clone this wiki locally