MatchmakingService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
MatchmakingService มีหน้าที่จัดการคุณสมบัติการจับคู่แบบกำหนดเอง ใช้เพื่ออ่านและเขียนข้อมูลการจับคู่
สรุป
วิธีการ
ดึงค่าของคุณสมบัติเซิร์ฟเวอร์เฉพาะได้
เริ่มต้นสคริปต์โครงสร้างค่าเซิร์ฟเวอร์และค่าของมันเพื่อทดสอบใน Studio
กำหนดค่าให้กับคุณสมบัติเซิร์ฟเวอร์เฉพาะ เช่น ค่า
คุณสมบัติ
วิธีการ
GetServerAttribute
ดึงค่าของคุณสมบัติเซิร์ฟเวอร์เฉพาะได้
พารามิเตอร์
ชื่อของคุณสมบัติเซิร์ฟเวอร์ จํากัดสูงสุด 50 ตัวอักษร
ส่งค่ากลับ
ส่งค่าคุณสมบัติเซิร์ฟเวอร์หากคุณสมบัติถูกพบและหากข้อผิดพลาดคือ nilมิฉะนั้นจะคืน nil สำหรับค่าคุณสมบัติและข้อความข้อผิดพลาด
InitializeServerAttributesForStudio
เริ่มสคริปต์โครงสร้างค่าเซิร์ฟเวอร์และค่าของมันเพื่อทดสอบใน Studio วิธีนี้เป็นตัวเลือกและไม่มีผลเมื่อทำงานนอกสตูดิโอ
พารามิเตอร์
ชุดของชื่อค่าตัวละครและค่าที่มีชื่อเป็นคู่
ส่งค่ากลับ
ส่งคืน true หากการโทรสําเร็จ มิฉะนั้นจะส่งคืน false และข้อความข้อผิดพลาด
SetServerAttribute
กำหนดค่าให้กับคุณสมบัติเซิร์ฟเวอร์เฉพาะ เช่น ค่า
พารามิเตอร์
ชื่อของคุณสมบัติเซิร์ฟเวอร์ จํากัดสูงสุด 50 ตัวอักษร
ค่าของคุณสมบัติเซิร์ฟเวอร์ จํากัดไว้ที่สูงสุด 50 ตัวอักษร
ส่งค่ากลับ
ส่งคืน true หากการโทรสําเร็จ มิฉะนั้นจะส่งคืน false และข้อความข้อผิดพลาด
ตัวอย่างโค้ด
The following code sample:
- Tests the hard-coded Level, Elo, and TrainingMode attributes in Studio with InitializeServerAttributesForStudio.
- Gets the Level attribute with GetServerAttribute.
- Updates the player's Level attribute with SetServerAttribute.
local MatchmakingService = game::GetService("MatchmakingService")
local RunService = game:GetService("RunService")
if RunService:IsStudio() then
-- Sets up initial attributes and schema for testing
MatchmakingService:InitializeServerAttributesForStudio(
{
Level = "Advanced",
Elo = 123.456,
TrainingMode = true
})
end
-- Retrieves the Level attribute
local currentLevel, error = MatchmakingService:GetServerAttribute("Level")
if error then
print(error)
else
print("Current level: " .. currentLevel)
end
-- Updates the Level attribute value to Advanced
local success, error = MatchmakingService:SetServerAttribute("Level", "Advanced")
if not success then
print("Failed to update server attribute [Level] to [Advanced] due to error: " .. error)
else
print("Successfully set [Level] to [Advanced]")
end