Leaderboard
ClassA leaderboard which can contain scores and information about participating users.
- Available on all platforms
A leaderboard which can contain scores and information about participating users. Accessible through the LeaderboardModule asset.
Index
Properties
Methods
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
readonlyname:string
The name of the leaderboard.
Since
Lens Scripting Version 275
orderingType
readonlyorderingType:OrderingType
How the leaderboard should be ordered.
ttlSeconds
readonlyttlSeconds: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
| Parameter | Type |
|---|---|
options | RetrievalOptions |
successCallback | (othersInfo, currentUserInfo?) => void |
failureCallback | (status) => void |
Returns
void
getTypeName()
staticgetTypeName():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
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
score | number |
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
| Parameter | Type |
|---|---|
score | number |
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
| Enumeration | Description |
|---|---|
| OrderingType | Describes how the leaderboard should be ordered. |
| UsersType | The type of user to be retrieved. |
Classes
| Class | Description |
|---|---|
| CreateOptions | The options for the leaderboard to be made. |
| RetrievalOptions | Describes the context for the leaderboard to be requested. |
| SafeUserRecord | Information for a user who submitted a score to the leaderboard, carrying only non-sensitive user data. Returned by Leaderboard#submitScoreSafeInfo. |
| UserRecord | Information for a user who submitted a score to the leaderboard. |