question

Greggory Addison avatar image
Greggory Addison asked

Why is UpdateUserReadOnlyData Adding To The Wrong Data Key

I've created a cloud script function that takes an argument called "InAttributeName" so that I may dynamically update an attribute of my choosing from code in Unreal. For some odd reason when I call this script it runs with no exceptions but somehow the attribute that I pass through is not incremented. Instead a new attribute is added to my player data and that one is incremented. What really blows my mind is that this new attribute that is added is the same name as my var "InAttributeName". How is this even possible and how do I fix it?

handlers.IncrementPlayerAttribute = function (args, context)
{
    // Get the current value of the attribute we are trying to increment
    var InAttributeName = args.AttributeName;
     
     var playerData = server.GetUserReadOnlyData({
        PlayFabId: currentPlayerId,
        Keys: [InAttributeName]
  });
  
   log.info(playerData);
   
    prevCount = playerData.Data[InAttributeName].Value;
    var prevInt = parseInt(prevCount, 10);
    var nextCount = (prevInt + 1).toString();


    // Update the user data
    var value = server.UpdateUserReadOnlyData({
        PlayFabId: currentPlayerId,
        Data:
        {
            InAttributeName: nextCount 
        }
    });
    
   
   // TESTING ONLY 
        playerData = server.GetUserReadOnlyData({
        PlayFabId: currentPlayerId,
        Keys: [InAttributeName]
  });
    
    log.info(playerData.Data[InAttributeName])
    
    
};

apisCloudScriptPlayer DataunrealTitle Data
error.jpg (255.5 KiB)
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.

Greggory Addison avatar image Greggory Addison commented ·

Just tested with a hard set variable and it works perfectly but when I try to pass the name of the attribute via the arguments it using the name of the variable I've set the arguments to fill. This has got to be a bug.

0 Likes 0 ·

1 Answer

·
Seth Du avatar image
Seth Du answered

Please refer to JS document on Computed property names. You need to add "[]" for a variable when it is referred as a key.

It will be like:

var value = server.UpdateUserReadOnlyData({
    PlayFabId: currentPlayerId,
    Data:
    {
        [InAttributeName]: nextCount 
    }
});

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.

Greggory Addison avatar image Greggory Addison commented ·

Thanks! I'm still super green with the java script syntax. I seen that you can use C# but I dont think I'm ready for that either lol

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]