question

henagames avatar image
henagames asked

Updating multiple Player Statistics at once

Hi - I seem to be having an issue with some of my API calls getting lost. In my game, I give the player the ability to unlock all locations (4 of them) via in-app purchase. I have all receipt validation with Google working fine.

The problem is that when a player purchases the locations, I loop through and run a "PurchaseLocation" script that fires off FOUR UpdatePlayerStatistics API call (one for each location just unlocked). These API calls seem to be failing without error, and randomly.

The expectation is that in Player Statistics, after purchasing the 'unlocklocations' item (and consuming it), four new statistics will appear: "Location1Unlocked = 1", "Location2Unlocked = 1", etc. What is happening is that I am getting random results. Sometimes only one statistic makes it, sometimes three of them, and always something different.

I suppose the question is: Am I firing off too many API calls all at once? It seems very random, and I'm not getting any errors, it actually doesn't even look like it's calling all four of them...but again, it's random.

Here is most of the code I'm using to do this. Again, there are no errors returned.

//When player purchases with RM, this is called four times. One for each Location purchased

public void PurchaseBackground(string background){
        if(background == Constants.LOCATION_2){
            PlayFabController.Instance.UpdateLocation2UnlockedStatistic();
        }
        if(background == Constants.LOCATION_3){
            PlayFabController.Instance.UpdateLocation3UnlockedStatistic();
        }
        if(background == Constants.LOCATION_4){
            PlayFabController.Instance.UpdateLocation4UnlockedStatistic();
        }
        if(background == Constants.LOCATION_5){
            PlayFabController.Instance.UpdateLocation5UnlockedStatistic();
        }
    }


//In PlayFabController.cs - There are 4 of these methods, one for each location

public void UpdateLocation2UnlockedStatistic(){
        if(CheckInternet.Instance.isconnectedToInternet) {
            if(PlayFabClientAPI.IsClientLoggedIn()) {
                PlayFabClientAPI.UpdatePlayerStatistics(new UpdatePlayerStatisticsRequest
                    {
                        Statistics = new List<StatisticUpdate>
                        {
                            new StatisticUpdate { StatisticName = "Location2Unlocked", Value = 1 },
                        }
                    },
                    result => {
                        OnLocation2UnlockedSuccess(result); },
                    error => {
                        OnLocation2UnlockedFail(error); });
            }
        }
    }
Player Data
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
pfnathan avatar image
pfnathan answered

Please note that rate limiting is overall for the client; when you are making lots of calls, it could push you to over the top, which is very inefficient. You should be adding the stats to a request in the loop, and once that is done, you only make “one” call to update states. Also, make sure to minimize calls as much as possible for efficiency and preventing draining battery from mobile devices (if this is a mobile game). Note: You will get an error back on call if you are over the rate limit and make sure to check all errors coming back from all calls you are making.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

henagames avatar image henagames commented ·

@pfnathan - Well, I feel stupid because that makes a whole lot of sense. I do this elsewhere in the game, I don't know why I didn't approach this the same way. Thanks!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.