UserSettings

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建

用户设置是一个单例对象,用于存储基本用户设置,这些设置在所有游戏中持续存在。目前,它只存储 UserGameSettings 对象。

您可以通过 UserSettings() 函数检索到这个对象的引用,该函数将它返回。

代码示例

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)

概要

方法

  • 如果指定的用户功能启用,返回真值。如果用户功能不存在,将发生错误。

  • Reset():()

    清除用户设置的保存状态,恢复其默认值。

继承自ServiceProvider方法

活动

继承自ServiceProvider活动

属性

方法

IsUserFeatureEnabled

如果指定的用户功能启用,返回真值。如果用户功能不存在,将发生错误。

这个函数检查一个列表的 FFlags,其名称以“用户”开头。该函数用于由 Roblox 创建的脚本使用,功能与 GlobalSettings:GetFFlag() 相似。

参数

name: string
默认值:""

返回

代码示例

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

()

清除用户设置的保存状态,将其值恢复为默认值。此函数在本地脚本中无法正确运行,因为它没有权限恢复 UserGameSettings 类中的所有属性。


返回

()

活动