UserSettings

Pokaż przestarzałe

*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.

Brak możliwości tworzenia

Ustawienia użytkownika są jedynym obiektem, który jest używany do przechowywania podstawowych ustawień użytkownika, które utrzymują się wszystkie gry.Obecnie przechowuje tylko obiekt UserGameSettings.

Możesz odzyskać odniesienie do tego obiektu za pomocą funkcji UserSettings(), która go zwraca.

Przykłady kodu

Podstawowy przykład tego, jak funkcja IsUserFeatureEnabled jest używana przez Roblox do kontroli pewnych funkcji.

Próbka funkcji użytkownika włączona IsUserFeatureEnabled

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)

Podsumowanie

Metody

  • Zwraca prawdę, jeśli włączona jest określona funkcja użytkownika. Spowoduje to błąd, jeśli funkcja użytkownika nie istnieje.

  • Reset():()

    Kasuje zapisany stan Ustawień użytkownika i przywraca jego domyślne wartości.

Metody odziedziczeni z: ServiceProvider

Metody

  • Zapis równoległy

    Zwraca usługę określoną przez podany klasztor, jeśli została już utworzona, błędy za nieważną nazwę.

  • Zwraca usługę z nazwą klasy żądaną, tworząc ją, jeśli nie istnieje.

Zdarzenia

Zdarzenia odziedziczeni z: ServiceProvider

Zdarzenia

Właściwości

Metody

IsUserFeatureEnabled

Parametry

name: string
Wartość domyślna: ""

Zwroty

Przykłady kodu

Próbka funkcji użytkownika włączona IsUserFeatureEnabled

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

()

Zwroty

()

Zdarzenia