object.nickname

类型 字符串
版本 发行版 2024.3703
关键字 steam、steamworks、getUserInfo、UserInfo、昵称
另请参阅 steamworks.getUserInfo()
steamworks.*

概述

一个 字符串,提供当前已登录用户分配给某个用户的昵称。如果已登录的用户未分配昵称,此字段将变成一个空字符串。通常情况下,如果可能,应显示用户的昵称而不是其个人资料名称。

如果 UserInfo 对象引用了当前已登录的用户,则昵称属性将始终是一个空字符串。

示例

local steamworks = require( "plugin.steamworks" )

-- Set the user ID of the friend to fetch information for
local friendSteamId = "FRIEND_ID"

-- Function used to print the above friend's nickname to the log
local function fetchFriendInfo()
    local userInfo = steamworks.getUserInfo( friendSteamId )
    if ( userInfo ) then
        -- Friend's info was successfully fetched
        print( "Nickame: " .. userInfo.nickname )
    else
        -- Friend's info has not yet been fetched from Steam
    end
end

-- Attempt to fetch the friend's information now
-- This might fail on app startup if not cached by the Steam client
fetchFriendInfo()

-- Called when info about one user has been received or changed
local function onUserInfoUpdated( event )
    if ( event.userSteamId == friendSteamId ) then
        fetchFriendInfo()
    end
end

-- Set up a listener to be invoked when user info has been received or changed
steamworks.addEventListener( "userInfoUpdate", onUserInfoUpdated )