ProcessStatistics
Apply a set of operations to the specified statistics. User (player) Statistics are defined through the brainCloud portal.
The operations available are much richer than the standard increment operation available via IncrementUserStats().
For example:
{
"INNING": "INC#1", // Increment by one
"INNINGSREM": "DEC#1", // Decrement by one
"OUTS": "RESET", // Reset to the defined initial value
"POINTS": "INC_TO_LIMIT#5#30", // Increment by 5, but to a max of 30
"PLAYERS": "SET#8", // Set to the specified value
"HIGHESTHR": "MAX#3", // Set to the specified value if larger
"ESTIMATE": "MIN#5", // Set to the specified value if smaller
"GAME" : "5" // Missing stat grammar will treat the operation as an increment
}
The above example would:
- Increment
INNINGby1 - Decrement
INNINGSREMby1 - Reset
OUTSto its pre-defined initial value - Increment
POINTSby5, but to a maximum of30 - Set
PLAYERSto8 - Set
HIGHESTHRto3, or remain at current higher value - Set
ESTIMATEto5, or remain at current lower value - Increment
GAMEby5
For the full statistics grammar see the statistics grammar section.
| Service | Operation |
|---|---|
| playerStatistics | PROCESS_STATISTICS |
Method Parameters
| Parameter | Description |
|---|---|
| statistics | The stats data to be passed to the method |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string statistics = "{\"DEAD_CATS\":\"RESET\",\"LIVES_LEFT\":\"SET#9\",\"MICE_KILLED\":\"INC#2\",\"MICE_MULTIPLIER\":\"INC_TO_LIMIT#2#20\",\"DOG_SCARE_BONUS_POINTS\":\"MAX#20\",\"TREES_CLIMBED_REQ\":\"MIN#5\"}";
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.PlayerStatisticsService.ProcessStatistics(statistics, successCallback, failureCallback);
const char *statistics = "{\"DEAD_CATS\":\"RESET\",\"LIVES_LEFT\":\"SET#9\",\"MICE_KILLED\":\"INC#2\",\"MICE_MULTIPLIER\":\"INC_TO_LIMIT#2#20\",\"DOG_SCARE_BONUS_POINTS\":\"MAX#20\",\"TREES_CLIMBED_REQ\":\"MIN#5\"}";
_bc->getPlayerStatisticsService()->processStatistics(statistics, this);
NSString *statistics = @"{\"DEAD_CATS\":\"RESET\",\"LIVES_LEFT\":\"SET#9\",\"MICE_KILLED\":\"INC#2\",\"MICE_MULTIPLIER\":\"INC_TO_LIMIT#2#20\",\"DOG_SCARE_BONUS_POINTS\":\"MAX#20\",\"TREES_CLIMBED_REQ\":\"MIN#5\"}";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc playerStatisticsService] processStatistics:statistics
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String statistics = "{\"DEAD_CATS\":\"RESET\",\"LIVES_LEFT\":\"SET#9\",\"MICE_KILLED\":\"INC#2\",\"MICE_MULTIPLIER\":\"INC_TO_LIMIT#2#20\",\"DOG_SCARE_BONUS_POINTS\":\"MAX#20\",\"TREES_CLIMBED_REQ\":\"MIN#5\"}";
this; // implements IServerCallback
_bc.getPlayerStatisticsService().processStatistics(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 = {
"DEAD_CATS": "RESET",
"LIVES_LEFT": "SET#9",
"MICE_KILLED": "INC#2",
"MICE_MULTIPLIER": "INC_TO_LIMIT#2#20",
"DOG_SCARE_BONUS_POINTS": "MAX#20",
"TREES_CLIMBED_REQ": "MIN#5"
};
_bc.playerStatistics.processStatistics(statistics, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var statistics = {
"DEAD_CATS": "RESET",
"LIVES_LEFT": "SET#9",
"MICE_KILLED": "INC#2",
"MICE_MULTIPLIER": "INC_TO_LIMIT#2#20",
"DOG_SCARE_BONUS_POINTS": "MAX#20",
"TREES_CLIMBED_REQ": "MIN#5"
};
ServerResponse result = await _bc.playerStatisticsService.processStatistics(statistics:statistics);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var statistics = {
"DEAD_CATS": "RESET",
"LIVES_LEFT": "SET#9",
"MICE_KILLED": "INC#2",
"MICE_MULTIPLIER": "INC_TO_LIMIT#2#20",
"DOG_SCARE_BONUS_POINTS": "MAX#20",
"TREES_CLIMBED_REQ": "MIN#5"
};
var playerStatisticsProxy = bridge.getPlayerStatisticsServiceProxy();
var postResult = playerStatisticsProxy.processStatistics(statistics);
if (postResult.status == 200) {
// Success!
}
{
"service": "playerStatistics",
"operation": "PROCESS_STATISTICS",
"data": {
"statistics": {
"DEAD_CATS": "RESET",
"LIVES_LEFT": "SET#9",
"MICE_KILLED": "INC#2",
"MICE_MULTIPLIER": "INC_TO_LIMIT#2#20",
"DOG_SCARE_BONUS_POINTS": "MAX#20",
"TREES_CLIMBED_REQ": "MIN#5"
}
}
}
JSON Response
{
"status": 200,
"data": {
"statistics": {
"TestStat": 162
}
}
}