question

Jérémie Fouché avatar image
Jérémie Fouché asked

Write JSON Arguments ?

Hello,

i dont understand how to write JSON arguments in TaskScheduled.

I want this result :

But when i run that :

Its Success but The PlayerData : "PlayerData2_JSON" is vanish

The cloudscprit is that :

handlers.UpdatePlayerData2_JSON = function (args, context) 
{
    var playerData2 = args.PlayerData2_JSON


    var updateUserDataResult = server.UpdateUserReadOnlyData({
        PlayFabId: currentPlayerId,
        Data: {
            PlayerData2_JSON: playerData2
        }
    });
};

So Whats wrong with my arguments at the second screenshot ?

Thank you for any help

CloudScript
screenshot-1.png (7.3 KiB)
screenshot-4.png (14.3 KiB)
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

·
Sarah Zhang avatar image
Sarah Zhang answered

Since, in fact, the data type of the player read-only data’s value is String. We simplified the value editing on Game Manager. So, you can edit the value as the JSON object using our built-in JSON Editor. But if you want to update it using API – UpdateUserReadOnlyData, you need to convert the value to JSON string first. The API call – UpdateUserReadOnlyData should work fine after you provide the data value that has the correct type. For your case, the data value should be something like this.

"{\"age\":42,\"name\":\"Isael\"}"

Specifically, you can edit [Arguments (JSON)] on the [Edit Scheduled Task] according to the parameters below.

"PlayerData2_JSON":"{\"age\":42,\"name\":\"Isael\"}"

Or you can add invoke of the JSON.stringify ([JSONObject]) method in you code to convert the JSON object to JSON string programmatically.

var playerData2 = JSON.stringify(args.PlayerData2_JSON);
2 comments
10 |1200

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

Jérémie Fouché avatar image Jérémie Fouché commented ·

Thank you, its what i needed.

0 Likes 0 ·
Jérémie Fouché avatar image Jérémie Fouché commented ·

Hello, i have no success anymore with your answer , PlayFab did change something about this process ?

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.