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 archiviare le impostazioni di base dell'utente, che persistono in tutti i giochi. Attualmente, 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 specificata dell'utente è abilitata. Questo mostrerà un errore se la funzione dell'utente non esiste.

  • Reset():void

    cancellato lo stato salvato delle impostazioni dell'utente, e restituisce i suoi valori predefiniti.

Metodi provenienti da ServiceProvider
  • Scrivi Parallelo

    Restituisce il servizio specificato dall'username specificato se è già stato creato, errori per un nome non valido.

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

Eventi

Eventi provenienti da ServiceProvider

Proprietà

Metodi

IsUserFeatureEnabled

Restituisce vero se la funzione specificata dell'utente è abilitata. Questo mostrerà un errore se la funzione dell'utente non esiste.

Questa funzione controlla una lista di bandiere, le quali iniziano con "User". La funzione è destinata ad essere utilizzata dagli script e funzioni Roblox create, e funziona allo stesso modo da GlobalSettings:GetFFlag() .

Parametri

name: string

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

void

Soversa lo stato salvato delle Impostazioni dell'Utente, e restaura i suoi valori predefiniti. Questa funzione non funzionerà correttamente da un LocalScript, poiché non ha il permesso di ripristinare tutte le proprietà nella classe UserGameSettings .


Restituzioni

void

Eventi