question

Ozan Yilmaz avatar image
Ozan Yilmaz asked

How to save JSON in player data?

Hello,

I have a function that runs when a new user is added to the title. I want to save a json in a player read only data. Here's the simplified version of the code:

handlers.NewUser = function(args, context) {
    var initialData = {
        "PlayfabId": currentPlayerId,
        "Data": {
            "SpeedPoints": 0,
            "Money": {
                "Cash": 0,
                "Bank": 1000
            }
        },
        "Permission": "Private"
    };
    server.UpdateUserReadOnlyData(initialData);
};

When I check the user's account, I can see the "SpeedPoints" key-value pair, however there is no "Money" key-value pair.

I want to combine some data to reduce the number of keys that I need to get in Cloudscript.

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

·
Citrus Yan avatar image
Citrus Yan answered

You must specify the key name of the combined data, and the value for the key should be a JSON string, please try this code:

handlers.NewUser = function(args, context) {


    var initialData = {
        "PlayfabId": currentPlayerId,
        "Data": {
            
            "Key1": JSON.stringify(
                {
                "SpeedPoints": 0,
                "Money": {
                    "Cash": 0,
                    "Bank": 1000
                    }
                }   
                )
        },
        "Permission": "Private"
    };
        server.UpdateUserReadOnlyData(initialData);
};
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.