UserSettings

Visualizza obsoleti

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.

Non costruibile

UserSettings è un oggetto singolo che viene utilizzato per ospitare le impostazioni utente di base, che persistono in tutti i giochi.Al momento, memorizza solo l'oggetto UserGameSettings .

Puoi recuperare un riferimento a questo oggetto tramite la funzione UserSettings(), che lo restituisce.

Campioni di codice

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)

Sommario

Metodi

  • Restituisce vero se la funzione utente specificata è abilitata. Ciò causerà un errore se la funzione utente non esiste.

  • Reset():()

    Cancella lo stato salvato delle UserSettings e ripristina i suoi valori predefiniti.

Metodi provenienti da ServiceProvider
  • Scrivi Parallelo

    Restituisce il servizio specificato dalla classe data se è già stato creato, errori per un nome non valido.

  • Restituisce il servizio con il nome di classe richiesto, creandolo se non esiste.

Eventi

Eventi provenienti da ServiceProvider

Proprietà

Metodi

IsUserFeatureEnabled

Restituisce vero se la funzione utente specificata è abilitata. Ciò causerà un errore se la funzione utente non esiste.

Questa funzione controlla contro una lista di FFlags, il cui nome inizia con "User".La funzione è destinata ad essere utilizzata da script creati da Roblox e funziona in modo simile a GlobalSettings:GetFFlag() .

Parametri

name: string
Valore predefinito: ""

Restituzioni

Campioni di codice

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

()

Cancella lo stato salvato delle impostazioni dell'utente e ripristina i suoi valori a predefinito.Questa funzione non riuscirà a eseguire correttamente da uno script locale, poiché non ha il permesso di ripristinare tutte le proprietà nella classe UserGameSettings.


Restituzioni

()

Eventi