MatchmakingService

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務
未複製

MatchmakingService 負責管理自定义匹配特性。使用它來閱讀和寫匹配數據。

屬性

方法

GetServerAttribute

取得特定伺服器特性的值。

參數

name: string

伺服器特性名稱。最多限於 50 個字元。

預設值:""

返回

如果找到特性並且錯誤為 nil ,則返回服務器特性值。否則,返回nil屬性值和錯誤訊息。

InitializeServerAttributesForStudio

啟動服務器屬性模型和其值在 Studio 進行測試。這個方法是可選的,在 Studio 之外運行時沒有效果。

參數

serverAttributes: Dictionary

一組屬性名稱值對。

預設值:""

返回

如果呼叫成功,返回 true;否則返回 false 和一個錯誤訊息。

SetServerAttribute

為特定伺服器屬性指派值。

參數

name: string

伺服器特性名稱。最多限於 50 個字元。

預設值:""
value: Variant

伺服器特性的值。限於最多 50 個字元。

預設值:""

返回

如果呼叫成功,返回 true;否則返回 false 和一個錯誤訊息。

範例程式碼

The following code sample:

MarketplaceService sample

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

活動