MatchmakingService

显示已弃用

*此内容使用人工智能(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

活动