UserSettings

Mostrar obsoleto

*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.

Não criável

O UserSettings é um objeto singleton que é usado para abrigar as configurações básicas do usuário, que persistem em todos os jogos.Atualmente, ele só armazena o ObjetoUserGameSettings .

Você pode recuperar uma referência a esse objeto através da função UserSettings(), que o retorna.

Amostras de código

A basic sample of how the IsUserFeatureEnabled function is used by Roblox to control certain features.

IsUserFeatureEnabled Sample

if UserSettings():IsUserFeatureEnabled("UserNoCameraClickToMove") then
print("'ClickToMove' should no longer be loaded from the CameraScript!")
else
print("'ClickToMove' is still loaded from the CameraScript!")
end

A LocalScript that demonstrates how you can detect whether a game is in full screen or not.

Full Screen Mode Detection

local gameSettings = UserSettings().GameSettings
local function checkFullScreenMode()
local inFullscreen = gameSettings:InFullScreen()
if inFullscreen then
print("Full Screen mode enabled!")
else
print("Full Screen mode disabled!")
end
end
checkFullScreenMode()
gameSettings.FullscreenChanged:Connect(checkFullScreenMode)

A basic example that shows how you can listen to changes in the user's settings. With this code pasted into a LocalScript running in the StarterPlayerScripts, you can change settings in Roblox's game menu, and see their values appear in the output as detected changes.

UserGameSettings Listener

local gameSettings = UserSettings().GameSettings
local function onGameSettingChanged(nameOfSetting)
-- Fetch the value of this setting through a pcall to make sure we can retrieve it.
-- Sometimes the event fires with properties that LocalScripts can't access.
local canGetSetting, setting = pcall(function()
return gameSettings[nameOfSetting]
end)
if canGetSetting then
print("Your " .. nameOfSetting .. " has changed to: " .. tostring(setting))
end
end
gameSettings.Changed:Connect(onGameSettingChanged)

Resumo

Métodos

  • Retorna verdadeiro se a característica de usuário especificada estiver habilitada. Isso gerará um erro se a característica de usuário não existir.

  • Reset():()

    Apaga o estado salvo das Configurações do Usuário e restaura seus valores padrão.

Métodos herdados de ServiceProvider
  • Escrever Parallel

    Retorna o serviço especificado pela classe dada se já for criado, erros por um nome inválido.

  • Retorna o serviço com o nome de classe solicitado, criando-o se não existir.

Eventos

Eventos herdados de ServiceProvider

Propriedades

Métodos

IsUserFeatureEnabled

Retorna verdadeiro se a característica de usuário especificada estiver habilitada. Isso gerará um erro se a característica de usuário não existir.

Essa função verifica contra uma lista de FFlags, cujo nome começa com "Usuário".A função é destinada a ser usada por scripts criados pelo Roblox e funciona de forma semelhante a GlobalSettings:GetFFlag().

Parâmetros

name: string
Valor Padrão: ""

Devolução

Amostras de código

A basic sample of how the IsUserFeatureEnabled function is used by Roblox to control certain features.

IsUserFeatureEnabled Sample

if UserSettings():IsUserFeatureEnabled("UserNoCameraClickToMove") then
print("'ClickToMove' should no longer be loaded from the CameraScript!")
else
print("'ClickToMove' is still loaded from the CameraScript!")
end

Reset

()

Apaga o estado salvo das Configurações do Usuário e restaura seus valores de volta ao padrão.Essa função falhará em executar corretamente a partir de um LocalScript, pois não tem permissão para restaurar todas as propriedades na classe UserGameSettings.


Devolução

()

Eventos