类型 函数 返回值 布尔值 修订版本 版本 2024.3703 关键词 steam, steamworks, 排行榜, requestSetHighScore 另请参见 steamworks.requestLeaderboardInfo() steamworks.requestLeaderboardEntries() setHighScore steamworks.*
异步将给定的分数发送到指定的排行榜。只有当给定分数高于用户先前分数时,排行榜才会接受该分数。
如果请求已成功发送到 Steam,则返回 true。请注意,这并不一定意味着请求的操作将会成功。例如,如果没有互联网连接,此函数将返回 true。因此,监听器必须检查接收到的 event.isError 属性,以确定请求的操作是否成功。
如果给出无效参数或 steamworks.isLoggedOn 属性为 false,则返回 false。
需要访问互联网才能在排行榜上设置高分。与成就和统计数据不同,Steam 不会在离线时缓存高分更新,并在互联网访问再次可用时将更改与 Steam 服务器重新同步。
steamworks.requestSetHighScore( params )
表. 包含参数的表 — 有关详细信息,请参阅下一节。
params 表可以包含以下内容
字符串. 要将高分发送到的排行榜的唯一名称。在 Steamworks 网站上,这是在**名称**列下设置的排行榜字符串。
函数. 将通过 setHighScore 事件接收请求结果的函数。
数字. 要作为新的高分上传到排行榜的整数值。
local steamworks = require( "plugin.steamworks" )
local function onReceivedSetHighScoreResult( event )
if ( event.isError ) then
-- The request has failed
-- Note that an error will not occur if the given score is less than the highest
print( "Failed to access the leaderboard." )
else
-- Print the result of this request to the log
print( "Leaderboard Name: " .. event.leaderboardName )
print( "Was Score Changed: " .. tostring(event.scoreChanged) )
if ( event.scoreChanged ) then
print( "Current Rank: " .. tostring(event.currentGlobalRank) )
print( "Previous Rank: " .. tostring(event.previousGlobalRank) )
end
end
end
-- Attempt to set a new high score for the current user
-- Requires an active Internet connection to succeed
-- Provides the requested result to the given "listener" function
local requestSettings =
{
leaderboardName = "My Leaderboard Name",
value = 9000,
listener = onReceivedSetHighScoreResult,
}
steamworks.requestSetHighScore( requestSettings )