Sign In Register

How can we help you today?

Start a new topic
Answered

Getting player leaderbord score Unity

Hello, I'm searching in your documentation, and can't seem to find a way to get the player score from the database.


I can manage to get the top 10 user leaderboards with this in the Test Harness:

  

{
 "@class": ".LeaderboardDataRequest",
 "leaderboardShortCode": "topScoreLeaderboard",
 "entryCount": "10",
 "requestId": "1406654736164"
}

   which would translate into this in unity:


 

GameSparksApi.leaderboardDataRequest("topScoreLeaderboard", 10).sendAsync(onResult);

How can I get the current players score and rank?


Thank you


Best Answer

You can either use


GetLeaderboardEntries


or


AroundMeLeaderboardDataRequest


G


Answer

You can either use


GetLeaderboardEntries


or


AroundMeLeaderboardDataRequest


G

There is a good example on getting the player scores using LeaderboardDataRequest here...
https://support.gamesparks.net/support/discussions/topics/1000066784


The score is not a field supplied in LeaderboardDataResponse that you can access in code. You need to refer to JSONData in the response.

The link shows you code for this.



I answered cloud code for leaderboard

var Scoresplayer = Spark.getData().Score;

var Levelplayer=Spark.getData().Level;

var requestLB = new SparkRequest.SocialLeaderboardDataRequest();

var responseLB = requestLB.Send();

var requestData = new SparkRequest.LeaderboardDataRespnse();

var responseData = requestData.Send();

var ScoreData = responseData.Score;

var scriptDataLB = responseLB.scriptData;

var scriptDataDB = responseData.scriptData;

var SendPlayerLevel = requestLB.Send().Level;

var SendPlayerScore = requestLB.Send().Score;

var SendPlayermyData = requesLB.getPlayer().getPlayerId();

var requestmyData ={"SendPlayerLevel":SendPlayerLevel,"SendPlayerScore":SendPlayerScore,"SendPlayermyData":SendPlayermyData }; function RequestData(){

   var LeadersData; responseLB.leaderboardShortCode("LB.Level"+i);

}

function setRequestData(){ var data = Spark.getData()["requesmyData"];

    Spark.setScriptData("scriptData",requestmyData);

}

function getRequestData(){ var data =Spark.getData()["scriptData"]["requestmyData"]; return data;

}

Login to post a comment