Skip to main content

Leaderboard

Class

A leaderboard which can contain scores and information about participating users.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

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

Index

Example

//@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);
}

Extends

Properties

name

readonly name: string

The name of the leaderboard.

Since

Lens Scripting Version 275


orderingType

readonly orderingType: OrderingType

How the leaderboard should be ordered.


ttlSeconds

readonly 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.

Since

Lens Scripting Version 275

Methods

getLeaderboardInfo()

getLeaderboardInfo(options, successCallback, failureCallback): void

Exposes user data

Get information about the leaderboard, such as who is on it. The records returned carry other users' full information, so this exposes user data and cannot be combined with network modules such as ConnectedLensModule.

Parameters

ParameterType
optionsRetrievalOptions
successCallback(othersInfo, currentUserInfo?) => void
failureCallback(status) => void

Returns

void


getTypeName()

static getTypeName(): TypeName<Leaderboard>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<Leaderboard>

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

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

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

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

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


submitScore()

submitScore(score, successCallback, failureCallback): void

Exposes user data

Submit a score to the leaderboard. The success callback hands back the submitting user's own record, which carries their full information, so this exposes user data and cannot be combined with network modules such as ConnectedLensModule. Use Leaderboard#submitScoreSafeInfo when the Lens also needs a network module.

Parameters

ParameterType
scorenumber
successCallback(currentUserInfo) => void
failureCallback(status) => void

Returns

void


submitScoreSafeInfo()

submitScoreSafeInfo(score, successCallback, failureCallback): void

Submit a score to the leaderboard, with a success callback that receives only non-sensitive user information. Unlike Leaderboard#submitScore this does not expose user data, so it can be used alongside network modules such as ConnectedLensModule.

Parameters

ParameterType
scorenumber
successCallback(currentUserInfo) => void
failureCallback(status) => void

Returns

void

Since

Lens Scripting Version 375

Example

//@input Asset.LeaderboardModule leaderboardModule

const options = Leaderboard.CreateOptions.create();
options.name = "highScores";
options.ttlSeconds = 64000;
options.orderingType = Leaderboard.OrderingType.Descending;

script.leaderboardModule.getLeaderboard(options, function (leaderboard) {
leaderboard.submitScoreSafeInfo(100, function (currentUserInfo) {
print(currentUserInfo.snapchatUser.name + " scored " + currentUserInfo.score);
}, function (status) {
print("submitScoreSafeInfo failed with status " + status);
});
}, function (message) {
print("getLeaderboard failed: " + message);
});

Nested types

Enumerations

EnumerationDescription
OrderingTypeDescribes how the leaderboard should be ordered.
UsersTypeThe type of user to be retrieved.

Classes

ClassDescription
CreateOptionsThe options for the leaderboard to be made.
RetrievalOptionsDescribes the context for the leaderboard to be requested.
SafeUserRecordInformation for a user who submitted a score to the leaderboard, carrying only non-sensitive user data. Returned by Leaderboard#submitScoreSafeInfo.
UserRecordInformation for a user who submitted a score to the leaderboard.