A class responsible for managing defined game settings or settings menus. Each setting is a string key/value pair belonging to a certain namespace and a certain store scope.

When Foundry Virtual Tabletop is initialized, a singleton instance of this class is constructed within the global Game object as game.settings.

Properties

settings: Map<string, SettingsConfig>

A object of registered game settings for this scope

menus: Map<any, any>

Registered settings menus which trigger secondary applications

storage: Map<string, Storage>

The storage interfaces used for persisting settings Each storage interface shares the same API as window.localStorage

Accessors

Methods

  • Register a new game setting under this setting scope

    Parameters

    • namespace: string

      The namespace under which the setting is registered

    • key: string

      The key name for the setting under the namespace

    • data: SettingConfig

      Configuration for setting data

    Returns void

    Example: Register a client setting

    game.settings.register("myModule", "myClientSetting", {
    name: "Register a Module Setting with Choices",
    hint: "A description of the registered setting and its behavior.",
    scope: "client", // This specifies a client-stored setting
    config: true, // This specifies that the setting appears in the configuration view
    requiresReload: true // This will prompt the user to reload the application for the setting to take effect.
    type: String,
    choices: { // If choices are defined, the resulting setting will be a select menu
    "a": "Option A",
    "b": "Option B"
    },
    default: "a", // The default value for the setting
    onChange: value => { // A callback function which triggers when the setting is changed
    console.log(value)
    }
    });

    Example: Register a world setting

    game.settings.register("myModule", "myWorldSetting", {
    name: "Register a Module Setting with a Range slider",
    hint: "A description of the registered setting and its behavior.",
    scope: "world", // This specifies a world-level setting
    config: true, // This specifies that the setting appears in the configuration view
    requiresReload: true // This will prompt the GM to have all clients reload the application for the setting to
    // take effect.
    type: new foundry.fields.NumberField({nullable: false, min: 0, max: 100, step: 10}),
    default: 50, // The default value for the setting
    onChange: value => { // A callback function which triggers when the setting is changed
    console.log(value)
    }
    });
  • Register a new sub-settings menu

    Parameters

    • namespace: string

      The namespace under which the menu is registered

    • key: string

      The key name for the setting under the namespace

    • data: SettingSubmenuConfig

      Configuration for setting data

    Returns void

    Example: Define a settings submenu which handles advanced configuration needs

    game.settings.registerMenu("myModule", "mySettingsMenu", {
    name: "My Settings Submenu",
    label: "Settings Menu Label", // The text label used in the button
    hint: "A description of what will occur in the submenu dialog.",
    icon: "fas fa-bars", // A Font Awesome icon used in the submenu button
    type: MySubmenuApplicationClass, // A FormApplication subclass which should be created
    restricted: true // Restrict this submenu to gamemaster only?
    });
  • Get the value of a game setting for a certain namespace and setting key

    Parameters

    • namespace: string

      The namespace under which the setting is registered

    • key: string

      The setting key to retrieve

    Returns any

    Example: Retrieve the current setting value

    game.settings.get("myModule", "myClientSetting");
    
  • Set the value of a game setting for a certain namespace and setting key

    Parameters

    • namespace: string

      The namespace under which the setting is registered

    • key: string

      The setting key to retrieve

    • value: any

      The data to assign to the setting key

    • Optional options: object = {}

      Additional options passed to the server when updating world-scope settings

    Returns any

    The assigned setting value

    Example: Update the current value of a setting

    game.settings.set("myModule", "myClientSetting", "b");
    
  • Assert that the namespace and setting name were provided and form a valid key.

    Parameters

    • namespace: string

      The setting namespace

    • settingName: string

      The setting name

    Returns string

    The combined setting key

  • Create or update a Setting document in the World database.

    Parameters

    • key: string

      The setting key

    • value: any

      The desired setting value

    • Optional options: object

      Additional options which are passed to the document creation or update workflows

    Returns Promise<Setting>

    The created or updated Setting document

  • Create or update a Setting document in the browser client storage.

    Parameters

    • key: string

      The setting key

    • value: any

      The desired setting value

    • onChange: Function

      A registered setting onChange callback

    Returns Setting

    A Setting document which represents the created setting