IncrementGlobalStats
Atomically increment (or decrement) global statistics. Global statistics are defined through the brainCloud portal.
StatisticsData like
{ "stat1" : 10, "stat2" : -5.5 }
would increment stat1 by 10 and decrement stat2 by 5.5. For the full statistics grammar see the statistics grammar section.
There are many more complex operations supported such as
{ "stat1" : "INC_TO_LIMIT#9#30" }
which increments stat1 by 9 up to a limit of 30.
Service | Operation |
---|---|
globalGameStatistics | UPDATE_INCREMENT |
Method Parameters
Parameter | Description |
---|---|
statistics | A collection containing the statistics to increment |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string statistics = "{\"PLAYER_COUNT\":1}";
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.GlobalStatisticsService.IncrementGlobalStats(statistics, successCallback, failureCallback);
const char *statistics = "{\"PLAYER_COUNT\":1}";
_bc->getGlobalStatisticsService()->incrementGlobalStats(statistics, this);
NSString *statistics = @"{\"PLAYER_COUNT\":1}";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc globalStatisticsService] incrementGlobalStats:statistics
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String statistics = "{\"PLAYER_COUNT\":1}";
this; // implements IServerCallback
_bc.getGlobalStatisticsService().incrementGlobalStats(statistics, 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 statistics = {
"PLAYER_COUNT": 1
};
_bc.globalStatistics.incrementGlobalStats(statistics, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var statistics = {
"PLAYER_COUNT": 1
};
ServerResponse result = await _bc.globalGameStatisticsService.incrementGlobalStats(statistics:statistics);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var statistics = {
"PLAYER_COUNT": 1
};
var globalStatisticsProxy = bridge.getGlobalStatisticsServiceProxy();
var postResult = globalStatisticsProxy.incrementGlobalStats(statistics);
if (postResult.status == 200) {
// Success!
}
var statistics = {
"PLAYER_COUNT": 1
};
var globalStatisticsProxy = bridge.getGlobalStatisticsServiceProxy();
var postResult = globalStatisticsProxy.incrementGlobalStats(statistics);
if (postResult.status == 200) {
// Success!
}
JSON Response
{
"status": 200,
"data": {
"statistics": {
"PLAYER_COUNT": 16
}
}
}