Global Rank shows sometimes and sometimes it does not

0 votes

When I click the button to show my local leaderboard my highscore always shows and it always shows "global rank: " but it does not always show the actual rank. My code is below. any help would be great thanks! 

 

if (GUI.Button (new Rect (820, 180, 220, 100), " Local \n Scores", GameFont2)) {
// Clearing Data From Response Box. 
success = "";
personalBest = "";
globalRanking = "";
 
UnityLeaderboardAsteroidAttack.success = "";
UnityLeaderboardAsteroidAttack.playerRank = "";
UnityLeaderboardAsteroidAttack.playerName = "";
UnityLeaderboardAsteroidAttack.playerScore = "";
UnityLeaderboardAsteroidAttack.errorLable = "";
UnityLeaderboardAsteroidAttack.box = "";
UnityLeaderboardAsteroidAttack.columnName = ""; 
 
if (txt_max == 0) {
 
return;
}
 
scoreBoardService = App42API.BuildScoreBoardService (); // Initializing scoreBoardService.
int max = txt_max; // Maximum Number Of TOP RANKERS.
string userName = LogIn.UserName; 
 
 
if (userName == "")
{
errorLable = "You can't see your scores without signing in!"; 
}
 
//Getting Top Scorers , By Using App42 Scoreboard Service.
//Method Name->GetTopNRankers(gameName, max);
//Param->gameName(Name Of The Game, Which Is Created By You In AppHQ.)
//Param->max(Provide Max Number "N" Of Scorers.)
//Param->Callback(callback for success/exception.);
//scoreBoardService.GetUserRanking (cons.gameName, userName, this);
scoreBoardService.GetHighestScoreByUser(cons.gameName, userName, this);
scoreBoardService.GetUserRanking (cons.gameName, userName, this);
leaderBoardButton = true;
//UnityLeaderboardAsteroidAttack.leaderBoardButton = false; 
 
localButton = true; 
 
// Reset matrix
GUI.matrix = Matrix4x4.identity;
}
 
}
 
//=======================================================================================
//---------------------------ON-SUCCESS OF APP42CALLBACK.--------------------------------------
//=======================================================================================
/// <summary>
/// Raises the success event.
/// </summary>
/// <param name="response">Response.</param>
public void OnSuccess (object response)
{
var nxtLine = System.Environment.NewLine; //Use this whenever i need to print something On Next Line.
 
Game gameResponseObj = (Game)response;
 
if (leaderBoardButton) {
leaderBoardButton = false;
IList<Game.Score> topRankersList = gameResponseObj.GetScoreList ();
 
if (topRankersList.Count > 0) {
 
for (int i = 0; i < gameResponseObj.GetScoreList().Count; i++) {
double highestScoreValue = gameResponseObj.GetScoreList () [i].GetValue ();
personalBest = "Highest Score: " + personalBest + highestScoreValue.ToString () + nxtLine; //Getting Player Name.
}
for(int i = 0;i<gameResponseObj.GetScoreList().Count;i++)  {
string GlobalRank = gameResponseObj.GetScoreList () [i].GetRank ();
globalRanking = "Global Ranking: " + GlobalRank;
}
 
}
}
}
asked Jun 30, 2014 in App42 Cloud API-BaaS by rnvitter (22 points)

1 Answer

+1 vote
 
Best answer

Hi rnvitter,

This problem occurs because you are calling two methods on single button click, 

scoreBoardService.GetHighestScoreByUser(cons.gameName, userName, this); // Doesn't Return Rank.

scoreBoardService.GetUserRanking (cons.gameName, userName, this);  // Returns Rank.

The methods are works in Async mode, due to which sometimes, the response of first method's comes first and sometimes the second method's response comes first, thats why you are getting global rank sometimes because the GetHighestScoreByUser method doesn't return Rank. So just comment this method then you'll get the rank everytime. 

 

answered Jul 1, 2014 by Akshay.Mishra (179 points)
selected Jul 1, 2014 by rnvitter
I need it to show highscore and global rank together, is there anyway to make it so it shows both with one button click?
Also if it only does one at a time why does the highscore method always show but the global rank only shows sometimes? Wouldnt the async mean that only one could be shown at a time?
you can just use the method GetUserRanking, it'll give you the userName, user's highest scoreValue and the userRank. i think it'll fullfill your requirements. Why you are using GetHighestScoreByUser whereas GetUserRanking will return HighestScoreValue with userRanking.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...