Skip to main content

SettingDefinitionProvider

Provides settings in bulk, and can be initialized by a ServiceBag. See SettingDefinition for more details on how to use this.

tip

These settings providers should be used on both the client and the server. On the client, these are registered with the SettingsDataService so that they can be shown in UI automatically if desired.

On the server, these are registered with SettingsDataService and then are checked before arbitrary data can e sent.

local SettingDefinition = require("SettingDefinition")

return require("SettingDefinitionProvider").new({
	KeyBinding = Enum.KeyCode.X;
	CameraShake = true;
	CameraSensitivity = 1;
})

Functions

new

SettingDefinitionProvider.new(settingDefinitions{SettingDefinition}) → SettingDefinitionProvider

Constructs a new provider with a list of SettingDefinition's.

-- In one location
local SettingDefinition = require("SettingDefinition")

return require("SettingDefinitionProvider").new({
	KeyBinding = Enum.KeyCode.X;
	CameraShake = true;
	CameraSensitivity = 1;
})

Usage:

local ourSettings = serviceBag:GetService(require("OurSettings"))

print(ourSettings.CameraShake:Get(Players.LocalPlayer), true)

ourSettings.CameraShake:Set(Players.LocalPlayer, false)

ourSettings.CameraShake:Promise(Players.LocalPlayer)
	:Then(function(cameraShake)
		print(cameraShake)
	end)

Init

SettingDefinitionProvider:Init(serviceBagServiceBag) → ()

Initializes the provider, storing the data in SettingsDataService

Start

SettingDefinitionProvider:Start() → ()

Starts the provider. Empty.

GetSettingDefinitions

SettingDefinitionProvider:GetSettingDefinitions() → {SettingDefinition}

Returns the setting definition

__index

SettingDefinitionProvider:__index(indexstring) → SettingDefinition

You can index the provider to get a setting. For example

local SettingDefinition = require("SettingDefinition")

local provider = require("SettingDefinitionProvider").new({
	KeyBinding = Enum.KeyCode.X;
	CameraShake = true;
	CameraSensitivity = 1;
})

local service = serviceBag:GetService(provider)

-- Write a setting
service.CamaraShake:GetLocalPlayerSettingProperty(serviceBag).Value = false

Get

SettingDefinitionProvider:Get(settingNamestring) → SettingDefinition

Gets a new setting definition if it exists

Destroy

SettingDefinitionProvider:Destroy() → ()

Cleans up the setting registration

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new provider with a list of [SettingDefinition]'s.\n\n```lua\n-- In one location\nlocal SettingDefinition = require(\"SettingDefinition\")\n\nreturn require(\"SettingDefinitionProvider\").new({\n\tKeyBinding = Enum.KeyCode.X;\n\tCameraShake = true;\n\tCameraSensitivity = 1;\n})\n```\n\nUsage:\n\n```lua\nlocal ourSettings = serviceBag:GetService(require(\"OurSettings\"))\n\nprint(ourSettings.CameraShake:Get(Players.LocalPlayer), true)\n\nourSettings.CameraShake:Set(Players.LocalPlayer, false)\n\nourSettings.CameraShake:Promise(Players.LocalPlayer)\n\t:Then(function(cameraShake)\n\t\tprint(cameraShake)\n\tend)\n```",
            "params": [
                {
                    "name": "settingDefinitions",
                    "desc": "",
                    "lua_type": "{ SettingDefinition }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "SettingDefinitionProvider"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 69,
                "path": "src/settings/src/Shared/Setting/SettingDefinitionProvider.lua"
            }
        },
        {
            "name": "Init",
            "desc": "Initializes the provider, storing the data in [SettingsDataService]",
            "params": [
                {
                    "name": "serviceBag",
                    "desc": "",
                    "lua_type": "ServiceBag"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 107,
                "path": "src/settings/src/Shared/Setting/SettingDefinitionProvider.lua"
            }
        },
        {
            "name": "Start",
            "desc": "Starts the provider. Empty.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 129,
                "path": "src/settings/src/Shared/Setting/SettingDefinitionProvider.lua"
            }
        },
        {
            "name": "GetSettingDefinitions",
            "desc": "Returns the setting definition",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ SettingDefinition }"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 138,
                "path": "src/settings/src/Shared/Setting/SettingDefinitionProvider.lua"
            }
        },
        {
            "name": "__index",
            "desc": "You can index the provider to get a setting. For example\n\n```lua\nlocal SettingDefinition = require(\"SettingDefinition\")\n\nlocal provider = require(\"SettingDefinitionProvider\").new({\n\tKeyBinding = Enum.KeyCode.X;\n\tCameraShake = true;\n\tCameraSensitivity = 1;\n})\n\nlocal service = serviceBag:GetService(provider)\n\n-- Write a setting\nservice.CamaraShake:GetLocalPlayerSettingProperty(serviceBag).Value = false\n```",
            "params": [
                {
                    "name": "index",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "SettingDefinition"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 173,
                "path": "src/settings/src/Shared/Setting/SettingDefinitionProvider.lua"
            }
        },
        {
            "name": "Get",
            "desc": "Gets a new setting definition if it exists",
            "params": [
                {
                    "name": "settingName",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "SettingDefinition"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 208,
                "path": "src/settings/src/Shared/Setting/SettingDefinitionProvider.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "Cleans up the setting registration",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 226,
                "path": "src/settings/src/Shared/Setting/SettingDefinitionProvider.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "SettingDefinitionProvider",
    "desc": "Provides settings in bulk, and can be initialized by a [ServiceBag]. See [SettingDefinition] for\nmore details on how to use this.\n\n:::tip\nThese settings providers should be used on both the client and the server. On the client, these\nare registered with the [SettingsDataService] so that they can be shown in UI automatically\nif desired.\n\nOn the server, these are registered with [SettingsDataService] and then are checked before\narbitrary data can e sent.\n:::\n\n```lua\nlocal SettingDefinition = require(\"SettingDefinition\")\n\nreturn require(\"SettingDefinitionProvider\").new({\n\tKeyBinding = Enum.KeyCode.X;\n\tCameraShake = true;\n\tCameraSensitivity = 1;\n})\n```",
    "source": {
        "line": 26,
        "path": "src/settings/src/Shared/Setting/SettingDefinitionProvider.lua"
    }
}