Sign In Register

How can we help you today?

Start a new topic
Answered

Easily add data to SocialLeaderboardDataRequest response

Hello,


We store some extra informations in every player's ScriptData (namely, type of medals and quantity of each medal earned). We are currently using a SocialLeaderboardDataRequest to fetch all a player's friends' scores, to display them in a leaderboard.


We would like to add some extra data to the response this request returns : we want, for each player for which a score was found (so for each entry in the data array returned in the response), go get the medals data in the player's ScriptData (something like player.getScriptData("bronzeMedals") for example) and add it to the player's leaderboard entry returned by the SocialLeaderboardDataRequest.


Is there an easy way to "append" this kind of data to the reponse sent by the request ? I know I can put Cloud Code in the SocialLeaderboardDataRequest event, but from my understanding this code is ran before the request is processed and the response generated, so I don't have yet the list of the player's friends, nor their IDs, etc. Is there a simple way to do what I want, or would I have to create a custom event that reproduces the request's behaviour and adds my own code to it ?


Thank you.


Best Answer

Hi,


The other solution would be to have a custom LogEventRequest which sends the SocialLeaderboardDataRequest as a SparkRequest in the Cloud Code script. You'll then be able to take the response and add anything you need to the entry objects. You can then set the results as scriptData in the response and the user can handle them accordingly on the client side.


Regards,

Liam


Hi,


You can set Supplemental attributes in your events. These can be tracked in your leaderboard and will be part of the entry itself. If you use this method you won't have to do any alterations to the response as the supplemental data is already part of the entry object. You can read more about this here.


Regards,

Liam



I'm not sure that would solve the issue. Supplemental attributes have to be filled in during the request, right ? I mean, as I call the request in my Java code, I have to fill out these attributes (or set a default value for them in the GameSparks interface), am I right ?


The issue is that the player (so the Java code) does not have these infos, they are already stored in GameSparks (in each player's scriptData in their profile).


Furthermore, these info have to be up to date. He could have submitted a score when he had, like, 2 medals, but now he has 5 and I need to reflect this when fetching scores (to display the medals for each player).

Answer

Hi,


The other solution would be to have a custom LogEventRequest which sends the SocialLeaderboardDataRequest as a SparkRequest in the Cloud Code script. You'll then be able to take the response and add anything you need to the entry objects. You can then set the results as scriptData in the response and the user can handle them accordingly on the client side.


Regards,

Liam

Login to post a comment