MatchmakingService
MatchmakingService is responsible for managing custom matchmaking attributes. Use it to read and write matchmaking data.
สรุป
วิธีการ
Retrieves the value of a specific server attribute.
Initiates the server attribute schema and its values to test in Studio.
Assigns a value to a specific server attribute.
คุณสมบัติ
วิธีการ
GetServerAttribute
Retrieves the value of a specific server attribute.
พารามิเตอร์
The name of the server attribute. Limited to a maximum of 50 characters.
ส่งค่ากลับ
Returns the server attribute value if the attribute is found and if the error is nil. Otherwise, returns nil for the attribute value and an error message.
InitializeServerAttributesForStudio
Initiates the server attribute schema and its values to test in Studio. This method is optional and has no effect when running outside of Studio.
พารามิเตอร์
An array of attribute name-value pairs.
ส่งค่ากลับ
Returns true if the call succeeded. Otherwise, returns false and an error message.
SetServerAttribute
Assigns a value to a specific server attribute.
พารามิเตอร์
The name of the server attribute. Limited to a maximum of 50 characters.
The value of the server attribute. Limited to a maximum of 50 characters.
ส่งค่ากลับ
Returns true if the call succeeded. Otherwise, returns false and an error message.
ตัวอย่างโค้ด
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