Class LeaderboardAbstract

A leaderboard which can contain scores and information about participating users. Accessible through the LeaderboardModule asset.

//@input Asset.LeaderboardModule leaderboardModule

const createOptions = getCreateOptions();
script.leaderboardModule.getLeaderboard(createOptions, getLeaderboardSuccessCallback, getLeaderboardFailureCallback);

function getCreateOptions() {
const options = Leaderboard.CreateOptions.create();
options.name = "leaderboardName";
options.ttlSeconds = 64000;
options.orderingType = Leaderboard.OrderingType.Descending;

return options;
}

function getRetrievalOptions() {
const retrievalOptions = Leaderboard.RetrievalOptions.create();
retrievalOptions.usersType = Leaderboard.UsersType.Friends;
retrievalOptions.usersLimit = 3;

return retrievalOptions;
}

function getLeaderboardSuccessCallback(leaderboard) {
print("[Leaderboard] getLeaderbaord success callback");
print("[Leaderboard] Leaderboard Name = " + leaderboard.name);
print("[Leaderboard] Ordering Type = " + leaderboard.orderingType);

const retrievalOptions = getRetrievalOptions();
leaderboard.getLeaderboardInfo(retrievalOptions, getInfoSuccessCallback, getInfoFailureCallback);
leaderboard.submitScore(100, submitScoreSuccessCallback, submitScoreFailureCallback);
}

function getLeaderboardFailureCallback(message) {
print("[Leaderboard] getLeaderboard failure callback with message " + message);
}

function getInfoSuccessCallback(othersInfo, currentUserInfo) {
print("[Leaderboard] getLeaderboardInfo success callback");

if (!isNull(currentUserInfo)) {
print(`[Leaderboard] Current User info: ${currentUserInfo.snapchatUser.displayName ? currentUserInfo.snapchatUser.displayName : ''} score: ${currentUserInfo.score}`);
}
othersInfo.forEach((userRecord, idx) => {
print(`[Leaderboard] ${idx + 1}. ${userRecord.snapchatUser.displayName ? userRecord.snapchatUser.displayName : ''} score: ${userRecord.score}`);
});
}

function getInfoFailureCallback(message) {
print("[Leaderboard] getLeaderboardInfo failure callback with message " + message);
}

function submitScoreSuccessCallback(currentUserInfo) {
print("[Leaderboard] submitScore success callback");
if (!isNull(currentUserInfo)) {
print(`[Leaderboard] Current User info: ${currentUserInfo.snapchatUser.displayName ? currentUserInfo.snapchatUser.displayName : ''} score: ${currentUserInfo.score}`);
}
}

function submitScoreFailureCallback(message) {
print("[Leaderboard] submitScore failure callback with message " + message);
}

Hierarchy (view full)

Constructors

Properties

name: string

The name of the leaderboard.

orderingType: OrderingType

How the leaderboard should be ordered.

ttlSeconds: number

How long entries on the leaderboard should last in seconds. Can be between 0-2 years. Setting 0 will result in default ttl which is 1 year. You must include this parameter when creating a leaderboard.

Methods

  • Get information about the leaderboard, such as who is on it.

    Parameters

    • options: RetrievalOptions
    • successCallback: ((othersInfo: UserRecord[], currentUserInfo?: UserRecord) => void)
        • (othersInfo, currentUserInfo?): void
        • Parameters

          Returns void

    • failureCallback: ((status: number) => void)
        • (status): void
        • Parameters

          • status: number

          Returns void

    Returns void

  • Returns true if the object matches or derives from the passed in type.

    Parameters

    • type: string

    Returns boolean

  • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

    Parameters

    Returns boolean

  • Submit a score to the leaderboard.

    Parameters

    • score: number
    • successCallback: ((currentUserInfo: UserRecord) => void)
        • (currentUserInfo): void
        • Parameters

          Returns void

    • failureCallback: ((status: number) => void)
        • (status): void
        • Parameters

          • status: number

          Returns void

    Returns void

MMNEPVFCICPMFPCPTTAAATR