Player Stats Management

Hello everyone,

I’m trying to integrate Player Statistics.

I’m using “UpdateUserStatItemsValue” method:

statistic.UpdateUserStatItemsValue(
            statCode,
            additionalKey,
            userStatItem,
            result => OnUpdateUserStatsFromClientCompleted(result, resultCallback)
        );

As per SDK code and documentation, “additionalKey” parameter should be not Null or Empty, so I’m getting stats records with “User ID = user_id_additionalKey” like this:


But I can’t get those records by original User ID:

And because of that, I suppose, I can’t get any records when trying to Invoke “GetUserStatItems” method by statCodes and currentUserId:

statistic.GetUserStatItems(
            statCodes,
            tags,
            result => OnGetUserStatsFromClientCompleted(result, resultCallback)
        );

How I should implement statistics update ?
Please help :slight_smile:

Hi @SirGray,

Did you already try with empty string? I believe assigning empty string to additionalKey should be enough.

string additionalKey = "";

Please let me know if it is not working.
Thanks.

Sorry, It seems this UpdateUserStatItemsValue method is indeed having a not Null or Empty validation, which is not intended. Let me inform the respective team.
In the meantime could you try using this method UpdateUserStatItems to update the stat while also set the additionalKey to empty?

Reference: Store additional data in user statistic | AccelByte Documentation

string additionalKey = "";
  
StatItemUpdate UserStatItem = new StatItemUpdate {
    statCode = " Your stat code ",
    updateStrategy = StatisticUpdateStrategy.INCREMENT, 
    value = 50,
    additionalData = new Dictionary<string, object>
    {
        {"characterName", "hero"},
        {"weapons", new [] {"sword"} }
    }
};
    
StatItemUpdate[] bulkUpdateUserStatItems = { UserStatItem };

AccelBytePlugin.GetStatistic().UpdateUserStatItems(additionalKey
    , bulkUpdateUserStatItems
    , result =>
    {
        if (result.IsError)
        {
            // Do something if UpdateUserStatItems an error
            Debug.Log($"Error UpdateUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
        }
        else
        {
            // Do something if UpdateUserStatItems been successful
        }
    });

Sorry for the inconveniences.

1 Like

Hi @tmubarok,

UpdateUserStatItems seems working well for me.
Thank you.

This issue is fixed on Unity SDK version 16.17.0, updating user stat using UpdateUserStatItemsValue method should work now when assigning empty string to additionalKey.

1 Like