Sign In Register

How can we help you today?

Start a new topic

Customize AroundMeLeaderboardResponse

Hi there,


i'm trying to customize in Cloud Code the "AroundMeLeaderboardResponse". 


What i want to achieve is to include some custom data about the player retrieved in the leaderboard request (for example custom image or rank that i store in a different collection).


So i started modifying the "AroundMeLeaderboardResponse" on cloud code, retrieve correctly all my data and add to a "myPlayersList" array of objects.


In the end i set the  scriptData: 


Spark.setScriptData( "playersList", myPlayersList);


I try in TestHarness and everything works fine, i can see all my custom data set in the scriptData object.


But when i try retrieve this data in the editor [Unity] i always have the scriptData = null while the other data (the leaderboard data) is correctly display.


Is it a weird bug or am i doing something wrong ? I already used scriptData and never had this kind if problems.


Thanks for the answers.


It looks weird scenario in-fact. 


Could you please paste [Unity code ] how you are receiving the scriptData info?


I assume you are targeting the right app id on preview dashboard and your unity app.


Thanks.



Sure, this is my code:


 

public void GetGeneralLeaderboard() {
       // Check if player is logged
	if(!UserManager.Instance.online)
		return;

	// TODO - Localize
	string msg = "Retrieving leaderboard";
	NGUIModalsPopUps.Instance.loadingWindow.Show(msg, null);

	new AroundMeLeaderboardRequest_HIGH_SCORE_LB().SetEntryCount(30).SetIncludeFirst(10).SetIncludeLast(10).Send((response) => {

		NGUIModalsPopUps.Instance.loadingWindow.Hide();

		if(response.HasErrors) {
			Debug.Log("[LeaderboardController] Error retrieving leaderboard");
		} else {
			leaderboardData = response.Data;

		GameSparks.Core.GSData scriptData = response.ScriptData;

		if(scriptData != null) {
			Debug.Log("Script Data VALID");

			object[] players = scriptData.GetObjectList("playersList").ToArray();
			PlayerData newPlayer = new PlayerData();
			foreach(object player in players) {
				var dic = (Dictionary<string, object>)player;
				newPlayer.avatar = dic["avatar"].ToString();
				newPlayer.playerId = dic["playerId"].ToString();
				newPlayer.playerName = dic["playerName"].ToString();
				newPlayer.rank = (int)dic["rank"];
				newPlayer.xP = (int)dic["xP"];

				System.Array.Resize(ref leaderboardPlayersData, leaderboardPlayersData.Length + 1);
				leaderboardPlayersData[leaderboardPlayersData.Length - 1] = newPlayer;
				}

				} else
					Debug.Log("Script Data NULL");

                                DisplayLeaderboard();
			}
		});
	}

 

I already use scriptData other time (for example to retrieve my players specific data) and never had this kind of issue.


Thanks again.

I don't see any error with the usage. This is increasing curiosity  on what else could be the error :)


Can you please paste here response of this. 


 

response.JSONString

 


Thanks.

No, even with response.JSONString i have this: "scriptData" : null


But today i checked again in TestHarness and have some weird error (yesterday everything were fine). 


It seems that i cannot retrieve some player data, here a piece of my Cloud Code in "AroundMeLeaderboardResponse".


 

var leaderboardData = Spark.getData().data;
   
    var playerList = [];
    
    if(leaderboardData && leaderboardData.length > 0)
    {
        for(var i = 0; i < leaderboardData.length; i++)
        {
            var player = Spark.loadPlayer(leaderboardData[i].userId)

            playerList.push(player);
        }
    }
}
Spark.setScriptData("playersList", playerList );

 

The issue is that some player data is null so CloudCode exit and don't set the scriptData in the response. I don't understand why didn't happen yesterday (some server-related issue ?)

Another strange things is why player is null. I mean i use Spark.loadPlayer with an id retrieved from the leaderboard list, and i cannot post score on the leaderboard if player doesn't exist. So why palyer is null ?


Anyway it happened only on some players (test player to be precise), so i deleted them and now everythings seems ok, i can correctly retrieve the scriptData in client side. 


Said that it's very strange behavoiur...


Thanks again for the reponse