PostScoreToLeaderboard
Post the players score to the given social leaderboard.
You can optionally send a user-defined json string of data with the posted score. This string could include information relevant to the posted score.
Note that the behavior of posting a score can be modified in the brainCloud portal. By default, the server will only keep the player's best score.
Service | Operation |
---|---|
leaderboard | POST_SCORE |
Method Parameters
Parameter | Description |
---|---|
leaderboardId | The leaderboard to post to. |
score | The score to post. |
data | Optional user-defined data to post with the score. (As of 5.3, when updating an existing score, if the data argument is null, the currently stored data value will be preserved.) |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string leaderboardId = "default";
int score = 10;
string jsonOtherData = "{\"nickname\":\"batman\"}";
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.LeaderboardService.PostScoreToLeaderboard(leaderboardId, score, jsonOtherData, successCallback, failureCallback);
const char *leaderboardId = "default";
int score = 10;
const char *jsonOtherData = "{\"nickname\":\"batman\"}";
_bc->getLeaderboardService()->postScoreToLeaderboard(leaderboardId, score, jsonOtherData, this);
NSString *leaderboardId = @"default";
int score = 10;
NSString *jsonOtherData = @"{\"nickname\":\"batman\"}";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc leaderboardService] postScoreToLeaderboard:leaderboardId
score:score
jsonOtherData:jsonOtherData
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String leaderboardId = "default";
int score = 10;
String jsonOtherData = "{\"nickname\":\"batman\"}";
this; // implements IServerCallback
_bc.getLeaderboardService().postScoreToLeaderboard(leaderboardId, score, jsonOtherData, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var leaderboardId = "default";
var score = 10;
var jsonOtherData = {
"nickname": "batman"
};
_bc.leaderboard.postScoreToLeaderboard(leaderboardId, score, jsonOtherData, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var leaderboardId = "default";
var score = 10;
var data = {
"nickname": "batman"
};
ServerResponse result = await _bc.leaderboardService.postScoreToLeaderboard(leaderboardId:leaderboardId, score:score, data:data);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var leaderboardId = "default";
var score = 10;
var jsonOtherData = {
"nickname": "batman"
};
var leaderboardProxy = bridge.getLeaderboardServiceProxy();
var postResult = leaderboardProxy.postScoreToLeaderboard(leaderboardId, score, jsonOtherData);
if (postResult.status == 200) {
// Success!
}
{
"service": "leaderboard",
"operation": "POST_SCORE",
"data": {
"leaderboardId": "default",
"score": 10,
"data": {
"nickname": "batman"
}
}
}
JSON Response
{
"status": 200,
"data": null
}