question

markasaadramzy99 avatar image
markasaadramzy99 asked

Azure function UpdatePlayerStatisticsAsync adding Statistics from List in a for loop

EDIT: oh sorry, incorrect category

I have a list of game modes and trying to add a set of statistics too each one of them as shown in the code snippet bellow.

The code logs the correct number of added stats, however the stats are not actually updated, when I check them in the Statistics tab on PlayFab, it's empty. But when I remove the for loop and only add the stats manually like "rank", it works so I'm guessing for loops break it for some reason.

Any ideas?

public static class Gamemodes {
        public static List<Gamemode> gamemodes = new List<Gamemode> {
            new Gamemode {shortName = "TDM"},
            new Gamemode {shortName = "FFA"},
            new Gamemode {shortName = "KD"},
            new Gamemode {shortName = "CP"},
            new Gamemode {shortName = "SAD"},
            new Gamemode {shortName = "LOCATE"}
        };
    }


var request = new PlayFab.ServerModels.UpdatePlayerStatisticsRequest { 
	PlayFabId = playFabID, 
	Statistics = new List<PlayFab.ServerModels.StatisticUpdate>() 
};

request.Statistics.Add(new PlayFab.ServerModels.StatisticUpdate { 
	StatisticName = "rank", Value = 0 
});

for (int i = 0; i < Gamemodes.gamemodes.Count; i++) {
        request.Statistics.Add(new PlayFab.ServerModels.StatisticUpdate { 
		StatisticName = $"{Gamemodes.gamemodes[i].shortName}_kills", Value = 0 
	});
        request.Statistics.Add(new PlayFab.ServerModels.StatisticUpdate { 
		StatisticName = $"{Gamemodes.gamemodes[i].shortName}_deaths", Value = 0 
	});
        request.Statistics.Add(new PlayFab.ServerModels.StatisticUpdate {
 		StatisticName = $"{Gamemodes.gamemodes[i].shortName}_assists", Value = 0 
	});
        request.Statistics.Add(new PlayFab.ServerModels.StatisticUpdate {
 		StatisticName = $"{Gamemodes.gamemodes[i].shortName}_headshots", Value = 0 
	});
        request.Statistics.Add(new PlayFab.ServerModels.StatisticUpdate {
 		StatisticName = $"{Gamemodes.gamemodes[i].shortName}_wins", Value = 0 
	});
        request.Statistics.Add(new PlayFab.ServerModels.StatisticUpdate {
 		StatisticName = $"{Gamemodes.gamemodes[i].shortName}_losses", Value = 0 
	});
}



log.LogInformation($"UpdatePlayerStatisticsAsync adding stats:{request.Statistics.Count}");

await server.UpdatePlayerStatisticsAsync(request);
apisCloudScript
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

·
markasaadramzy99 avatar image
markasaadramzy99 answered

Fixed.
The issue had nothing to do with this part, I just refactored the code and it worked.

EDIT: It wasn't actually fixed. The real problem was that I had a limit on how many statistics I can update per call.
There should definitely be an error when you try to update more than the limit, I've been debugging this for the whole day.

10 |1200

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

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.