Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

IF you have used Game Center Social.Loadscores, PLEASE HELP ME

Discussion in 'iOS and tvOS' started by silverJEM, Jul 13, 2014.

  1. silverJEM

    silverJEM

    Joined:
    Aug 29, 2012
    Posts:
    9
    Okay i may hopefully solve this before i get help here, but I am stuck with a very simple task that has wasted a lot of time.

    I am attempting to show the "Top score to beat" on my title page of my game, which should pull the value from the Game Center leaderboard, of which i have one.

    It works but is giving me all scores instead of just the top.. here is my code.. where do i set it to only fill in just the top score (I'm thinking it has to do with the "foreach (IScore score in scores)" line

    public void LoadTopScore(){
    Social.LoadScores(dailyLeaderboardID, scores => {
    if (scores.Length > 0 ) {
    Debug.Log ("Got " + scores.Length + " scores");
    string myScores = "";
    foreach (IScore score in scores)
    myScores += "\t"+ score.formattedValue + "";
    topScore.text = (myScores);
    }
    else
    Debug.Log ("No scores loaded");
    });

    Thanks
     
  2. silverJEM

    silverJEM

    Joined:
    Aug 29, 2012
    Posts:
    9
    i think what I'm asking for is how to go from the foreach array command to just a for to pull the first score in the IScore score array
     
  3. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    Just load all the scores into an array and the first entry will be the highest.
     
  4. silverJEM

    silverJEM

    Joined:
    Aug 29, 2012
    Posts:
    9
    OK i solved it.. Instead of accessing the leaderboard array and pulling all of the data with a foreach loop, since thats the only example code given.. i rewrote it with just a declaration for first index in array..

    public void LoadTopScore(){
    Social.LoadScores(dailyLeaderboardID, scores => {
    if (scores.Length > 0 )
    {
    string myScores = "\t"+ scores[0].formattedValue + "";
    topScore.text = (myScores);
    }
    else
    Debug.Log ("No scores loaded");
    });
    }

    this drops the highest score into a text mesh to display in game.. now i can't seem to call the update immediately when the game starts but ill compromise instead of spending another 6 hours confused.
     
  5. silverJEM

    silverJEM

    Joined:
    Aug 29, 2012
    Posts:
    9
    This is the final cleaned up version... I am surprised this wasn't an easier thing to find on the net, which is mainly why I'm leaving my solution :)


    public void LoadTopScore(){
    Social.LoadScores(dailyLeaderboardID, scores => {
    if (scores.Length > 0 ) {
    string myScores = scores[0].formattedValue;
    topScore.text = (myScores);
    }
    else
    topScore.text = ("LOADING");
    });
    }
     
  6. Gul1

    Gul1

    Joined:
    Aug 31, 2013
    Posts:
    3
    whats the dailyLeaderboardID ? its the same which we put in ReportScore
     
  7. Gul1

    Gul1

    Joined:
    Aug 31, 2013
    Posts:
    3
    its showing 0 score