I've been moving my player stat update calls from the client to cloud script, but I'm running into this issue where the GetLeaderboard request is failing because it's "missing" the StatisticName field. The error logs out with this as the request:
{"StartPosition":0,"MaxResultsCount":1}
So StatisticName is getting lost somewhere and I don't know why.
CloudScript functions:
handlers.SubmitStatisticUpdate = function (args) { if (args && args.hasOwnProperty("StatisticUpdate")) { var statUpdate = args.StatisticUpdate; if (statUpdate.hasOwnProperty("StatisticName") && statUpdate.hasOwnProperty("Value")) { // Ensure there's already a valid leaderboard with this stat name // We do not want to create another leaderboard with whatever value was injected var statValidResult = ValidateStatistic(args); if (!statValidResult.Valid) { return { Success: false, Message: statValidResult.Message }; } // Ensure the score "adds up" var scoreValidResult = ValidateScore(args); if (!scoreValidResult.Valid) { return { Success: false, Message: scoreValidResult.Message }; } try { // Tell the server to update this Player's score for this Statistic var updateResult = server.UpdatePlayerStatistics( { PlayFabId: currentPlayerId, Statistics: [{ statUpdate }], }); return { Success: true, Result: result }; } catch(ex) { // If the update call failed, tell us why return { Success: false, Message: "UpdatePlayerStatistics failed: " + JSON.stringify(ex) }; } } return { Success: false, Message: "Did not receive required StatisticName or Value parameters" }; } return { Success: false, Message: "Did not receive required UpdateStatisticsRequest parameter" }; }; function ValidateStatistic(args) { try { var result = server.GetLeaderboard( { StatisticName: args.StatisticName, StartPosition: 0, MaxResultsCount: 1, }); return { Valid : true }; } catch (ex) { return { Valid : false, Message: "Couldn't get Statistic: " + JSON.stringify(ex) }; } };