leaderboardEntries

Type Event
Revision 2017.3060
Keywords steam, steamworks, leaderboard, leaderboardEntries
See also steamworks.requestLeaderboardEntries()
steamworks.*

Overview

Event providing an array of entries requested from a leaderboard.

This event can only be received by a function listener that has been passed to the steamworks.requestLeaderboardEntries() function.

Properties

Example

local steamworks = require( "plugin.steamworks" )

-- Called by the "steamworks.requestLeaderboardEntries()" function with the result
local function onReceivedLeaderboardEntries( event )
    if ( event.isError ) then
        -- Request failed; typically happens when there is no Internet access
        print( "Failed to fetch leaderboard entries." )
    else
        -- Print the received leaderboard entries to the log
        for index = 1, #event.entries do
            -- Get the next leaderboard entry
            local nextEntry = event.entries[index]

            -- Fetch the user's nickname via their steam ID
            local userName = "Unknown"
            local userInfo = steamworks.getUserInfo( nextEntry.userSteamId )
            if ( userInfo ) then
                userName = userInfo.nickname
            end

            -- Print the leaderboard entry to the log
            local message = string.format(
                "Rank(%d) Name(%s) Score(%d)",
                nextEntry.globalRank, userName, nextEntry.score )
            print( message )
        end
    end
end

-- Fetch the top 10 players on the leaderboard
-- Requires an active Internet connection to succeed
-- Will provide the requested result to the given listener function
local requestSettings =
{
    leaderboardName = "My Leaderboard Name",
    playerScope = "Global",
    startIndex = 1,
    endIndex = 10,
    listener = onReceivedLeaderboardEntries
}
steamworks.requestLeaderboardEntries( requestSettings )