UserSettings
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
การตั้งค่าผู้ใช้เป็นวัตถุโดดเดี่ยวที่ใช้เพื่อเก็บการตั้งค่าผู้ใช้พื้นฐานซึ่งยังคงอยู่ในทุกเกมขณะนี้มันเก็บวัตถุ UserGameSettings เท่านั้น
คุณสามารถดึงการอ้างอิงถึงวัตถุนี้ผ่านฟังก์ชัน UserSettings() ซึ่งส่งคืนมัน
ตัวอย่างโค้ด
A basic sample of how the IsUserFeatureEnabled function is used by Roblox to control certain features.
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.
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.
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)
สรุป
วิธีการ
ส่งคืนค่าจริงหากคุณลักษณะผู้ใช้ที่ระบุเปิดใช้งานแล้ว จะส่งข้อผิดพลาดหากคุณลักษณะผู้ใช้ไม่มีอยู่
ลบสถานะที่บันทึกของ UserSettings และฟื้นค่าเริ่มต้นกลับ
คืนบริการที่ระบุโดย className ที่กำหนดถ้ามันถูกสร้างขึ้นแล้ว ข้อผิดพลาดสำหรับชื่อที่ไม่ถูกต้อง
คืนบริการด้วยชื่อคลาสที่ร้องขอ โดยสร้างขึ้นถ้าไม่มีอยู่
อีเวนต์
อีเวนต์รับทอดมาจากServiceProviderเกิดไฟไหม้เมื่อสถานที่ปัจจุบันถูกออก
ยิงเมื่อบริการถูกสร้าง
ยิงเมื่อบริการกำลังจะถูกลบออก
คุณสมบัติ
วิธีการ
IsUserFeatureEnabled
ส่งคืนค่าจริงหากคุณลักษณะผู้ใช้ที่ระบุเปิดใช้งานแล้ว จะส่งข้อผิดพลาดหากคุณลักษณะผู้ใช้ไม่มีอยู่
ฟังก์ชันนี้ตรวจสอบกับรายการของ FFlags ที่ชื่อเริ่มต้นด้วย "ผู้ใช้"ฟังก์ชันมีจุดมุ่งหมายเพื่อใช้โดยสคริปต์ที่สร้างโดย Roblox และทำงานคล้ายกับ GlobalSettings:GetFFlag()
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
A basic sample of how the IsUserFeatureEnabled function is used by Roblox to control certain features.
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
ลบสถานะที่บันทึกของ UserSettings และนำค่ากลับไปเป็นค่าเริ่มต้นฟังก์ชันนี้จะไม่สามารถทำงานได้อย่างถูกต้องจาก LocalScript เนื่องจากไม่มีสิทธิ์ในการฟื้นคืนคุณสมบัติทั้งหมดในคลาส UserGameSettings