16

I use Google Play Games Services Unity Plugin to build an Android game as described in: https://github.com/playgameservices/play-games-plugin-for-unity

The problem:

When I load scores using the API (Social API or PlayGamesPlatform.Instance object of the google play plugin), I get out of date scores. But, when I use ShowLeaderBoardUI() function instead, the scores are correct in the GUI.

So there is no problem in posting the scores.

I use the following snippet to load user scores from the Google Play Game Services ScoreBoard:

void LoadUsersAndDisplay(int leaderBoardID,ILeaderboard lb,LeaderBoardEntry[] resultingEntries)
    {
        // get the user ids
        List<string> userIds = new List<string>();

        foreach(IScore score in lb.scores) {
            userIds.Add(score.userID);
        }
        // load the profiles and display (or in this case, log)
        PlayGamesPlatform.Instance.LoadUsers(userIds.ToArray(), (users) =>
            {
                string status = "Leaderboard loading: " + lb.title + " count = " +
                    lb.scores.Length;
                int currentUserIndex = 0;
                foreach(IScore score in lb.scores) {
                    IUserProfile user = users[currentUserIndex];


                    status += "\n" + score.formattedValue + " by " +
                        (string)(
                            (user != null) ? user.userName : "**unk_" + score.userID + "**");

                    resultingEntries[currentUserIndex] = new LeaderBoardEntry(score.rank,user.userName,score.value);
                    currentUserIndex++; 
                }

                // Get the local user score
                LeaderBoardEntry localUserEntry = new LeaderBoardEntry(lb.localUserScore.rank, Social.localUser.userName,lb.localUserScore.value);

                // Notify the observers about the receiving of the scores
                foreach (LeaderBoardObserver currentObserver in observers) {
                    Debug.Log ("Notifying the leaderboard observer");
                    currentObserver.OnScoresReceived (leaderBoardID,resultingEntries,localUserEntry);
                }

                Debug.Log(status);
            });
    }


public void getScores(int lbID){

        ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard();
        lb.id = leaderboards [lbID].lbOfficialID;
        lb.timeScope = TimeScope.AllTime;
        lb.userScope = UserScope.Global;
        LeaderBoardEntry[] resultingEntries = null;

        lb.LoadScores(ok =>
            {
                if (ok) {
                    resultingEntries = new LeaderBoardEntry[lb.scores.Length];
                    LoadUsersAndDisplay(lbID,lb,resultingEntries);
                }
                else {
                    Debug.Log("Error retrieving leaderboardi");
                }
            });


        Debug.Log ("Have " + observers.Count + " lbObservers");
    }

I have the following output when I print the received leaderboard:

>>Leaderboard loading: Quick Reaction Mode World Ranking count = 1
>>I/Unity   (16088): 45 by firatercis

But when I display all times scores for global users, I have the following screenshot:

enter image description here

First, the scoreboard was empty, I scored 45 points. I saw the 45 point in both sides there was no problem. Then I scored 50. But the result I achieved by the API never never updates.

I deleted and re-installed the game, nope. I cleaned the cache of the application, and there shouldn't be any copy of the number 45 anywhere, but I constantly get 45 points by using the API. Please help, where may I be wrong?

fercis
  • 611
  • 2
  • 12
  • 26
  • 1
    Just one thought; for this very reason, almost everyone just uses the Prime31 plug in for GPGS. (Google's own software is a joke, of course.) It sucks to have to pay a few bucks, and it's still a big nuisance, bit it's often the only way forward. – Fattie Nov 27 '16 at 11:24
  • Thanks, that was a valuable information, if I cannot solve this bug (I work on it for 2 weeks) I will think it as an option. – fercis Nov 27 '16 at 11:31
  • Really sorry to hear about the 2 weeks. Yes, GPGS is a total pain in the ass. Is your game on BOTH is and android, or just android? https://prime31.com/docs#androidPlayGameServices – Fattie Nov 27 '16 at 11:36
  • Getting your manifests and AAR files correct is a total nightmare. – Fattie Nov 27 '16 at 11:40
  • Each time you get a high score, you are suppose to post the score. Are you even doing that? You post it with `Social.ReportScore` – Programmer Nov 27 '16 at 13:46
  • @Programmer, yes, I just did not include that part on the post. I call exactly Social.ReportScore() each time the game ends (not only high score, in documentation I understand that GPGS eliminates non-high score posts). The problem is not in posting, because ShowLeaderBoardGUI() function displays the correct scores. – fercis Nov 27 '16 at 14:24
  • @JoeBlow Our game will be for both android and ios, but first we are soft launching our game in Android first. I tried just a little while, I guess porting GPGS to ios in Xcode will be another headache – fercis Nov 27 '16 at 14:27
  • 1
    It is more headache than you can ever imagine :O the prime31 dudes have a combo pack, meaning the one prime31 plugin works in your IOS build and in your ANDRDOID build, to connect to GPGS. https://prime31.com/docs#comboPlayGameServices – Fattie Nov 27 '16 at 15:19
  • Ahahah :D This bug converted my programming life just to a situation comedy. Prime31 combo pack can be only purchased by paypal which is not supported in my country – fercis Dec 03 '16 at 08:11

3 Answers3

1

I solved this problem by change LeaderboardManager.LoadLeaderboardData() to use Types.DataSource.NETWORK_ONLY vs. CACHE_OR_NETWORK.

Hema
  • 11
  • 1
0

Ensure that the settings of the leaderboard on the Google Play Developer Console are as you intended. In particular, ensure that Ordering is indeed set to "Larger is better" and that you do not have any Limits sets. Perhaps toggling "Enable tamper protection" is also a good idea...

I would have written this up as a comment and requested some clarification, but I don't have the reputation points. :(

Alistair Jones
  • 553
  • 4
  • 10
0

Might be your configuration not completed as shown in documentation :

Add achievements and leaderboards to your game in the Google Play Developer Console. For each achievement and leaderboard you configure, make sure to note the corresponding achievement ID or leaderboard ID, as those will be needed when making the API calls. Achievement and leaderboard IDs are alphanumeric strings (e.g. "Cgkx9eiuwi8_AQ").

Please recheck your code..

Kumar Rakesh
  • 2,718
  • 2
  • 18
  • 39