steamworks.getAchievementInfo()

类型 函数
返回值 AchievementInfo
修订版本 版本 2024.3703
关键词 steam, steamworks, 成就, getAchievementInfo
另请参阅 steamworks.requestUserProgress()
steamworks.setAchievementUnlocked()
steamworks.*

概述

返回一个 AchievementInfo 对象。它提供了有关一项成就的信息,例如其本地化名称、描述、解锁状态等,适用于当前登录的用户(或其他用户)。

获取其他用户的成就信息时,必须先使用该用户的 ID 调用 steamworks.requestUserProgress() 函数,并等待成功的 userProgressUpdate 事件。

注意事项

在以下情况下,此函数将返回 nil

语法

steamworks.getAchievementInfo( achievementName [, userSteamId] )
achievementName (必填)

字符串 在 Steamworks 网站上,这是在API 名称进度统计列下设置的成就的唯一名称。

userSteamId (可选)

字符串 用户的唯一字符串 ID。如果未提供此参数,则 ID 将默认为当前用户。

示例

local steamworks = require( "plugin.steamworks" )

-- Called when achievement status or stat data has been updated/changed
-- This will be called for the currently logged in user, and other users too
local function onUserProgressUpdated( event )
    -- Determine who this progress update is for
    if ( event.userSteamId == steamworks.userSteamId ) then
        print( "Received progress info for current user." )
    else
        print( "Received progress info for another user." )
    end

    -- Print the user's current achievement info
    local achievementInfo = steamworks.getAchievementInfo( "MyAchievementName", event.userSteamId )
    if ( achievementInfo ) then
        print( "  Localized Name: " .. achievementInfo.localizedName )
        print( "  Localized Description: " .. achievementInfo.localizedDescription )
        print( "  Is Hidden: " .. tostring(achievementInfo.hidden) )
        print( "  Was Unlocked: " .. tostring(achievementInfo.unlocked) )
        if ( achievementInfo.unlocked ) then
            -- Note that "unlockTime" is in local Unix time
            -- This can be compared with "os.time()" and used by "os.date()"
            print( "  Unlock Time: " .. os.date( "%c", achievementInfo.unlockTime ) )
        end
    end
end

-- Listen for achievement status or stat data changes from all users
steamworks.addEventListener( "userProgressUpdate", onUserProgressUpdated )