question

milox avatar image
milox asked

[CloudScript] Iterating through leaderboard results?

I'm having trouble with a little cloudscript. I'm trying to get a leaderboard for a given stat, and for each result I want to get more data from user data like country, lvl etc.. But I'm stuck, I'm a total javascript noob, I hate it, and the fact that I have to upload every revision to test it doesn't make it more pleasant. And the docs on cloudscript are very lacking. How do I iterate through the friggin' leaderboard data, then create a new array with leaderboard values and additional values from user data? Here's my non functional code:

handlers.getLeaderboardsWithPlayerData = function (args) {


//statName, int startPos, int maxResults
var statName = args.statName;
var startPos = args.startPos;
var maxResults = args.maxResults;
//get leaderboards
//for each player id get details

var leaderboard = server.GetLeaderboard({
StatisticName: statName,
StartPosition: startPos,
MaxResultsCount: maxResults
});

var ret = {};
var val;
for(var key in leaderboard["leaderboard"]) {
val = leaderboard["leaderboard"][key];
log.debug("Value" + val.toString());
}
//var l = leaderboard.length;
for(i=0; i<=leaderboard.length - 1; i++){
var playerId = leaderboard[i].Data["PlayFabId"];
ret["PlayFabID"] = playerId;
var playerData = server.GetUserData({PlayFabId : playerId, Keys : ["xp", "cash", "lvl", "country_code"]});
ret["PlayFabID"] = playerId;
ret["DisplayName"] = leaderboard.Data["DisplayName"];
ret["StatValue"] = leaderboard.Data["StatValue"];
ret["Position"] = leaderboard.Data["Position"];
//ret["Data"] = playerData.Data;
}

log.debug("Return player data " + val.toString());

return { val: val };
}

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Actually, the reason we don't describe doing something like this is because it's not viable. Iterating across the players returned in a leaderboard and taking some action on each would hit our service with far more calls that are allowed by our Terms of Service, even if this was being done on the client. In Cloud Script, the specified limit is that in one call, a script - which is to say any handler you call from the client plus any script functions it calls - can only make up to 10 Server API calls. It's possible to increase that limit (and the others) via a custom contract with us (our limits are for the free service - if you need higher limits, we can work out a price plan for covering the additional usage), but in the case of Cloud Script we would still need to review the design goals with you.

We'll be introducing additional columns of data for leaderboards later this year. For now, if you want to display extra data about players, the best plan is to allow players to click on an entry in the leaderboard to get an interface which shows the additional data. That way, you only need to call for that data at the rate the user is actually clicking for more info, which should be within the bounds of our ToS.

 

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

milox avatar image
milox answered

OK, I guess I'll have to simplify my leaderboards. But the ability to add data to leaderboards would be great. 

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.