question

Kim Strasser avatar image
Kim Strasser asked

I have a problem when I want to create a new key/value pair with server.UpdateUserReadOnlyData

I have a problem with server.UpdateUserReadOnlyData. It creates the following key/value pair:

The problem is that the key is "leaderboardname" but it should be the value of var leaderboardname.

For example, if the value of var leaderboardname = Leaderboardlevel1

Then, the key/value pair in UserReadOnlyData should be like this:

Leaderboardlevel1 1.5

What is wrong with my code? Why is the key not created correctly?

var currentlevel = args.Level;
var leveldata = args.LevelData;
var leaderboardname = "Leaderboardlevel" + currentlevel;
var updatereadonlydata = UpdateReadOnlyData(leaderboardname, leveldata);

function UpdateReadOnlyData(leaderboardname, leveldata)
{
    var result = server.UpdateUserReadOnlyData({
           PlayFabId: currentPlayerId,
           Data: {
               leaderboardname: leveldata
           },
           Permission: UserDataPermission.Public
        });
        
    if ((result != null) && (result.Error == null))
        return true;
    else
        return false;
}
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

·
Seth Du avatar image
Seth Du answered

Cloud Script is based on Google V8 JavaScript engine, and I am not sure if it is caused by JavaScript it self’s grammar usage. But here is a quick solution:

You may define an object first and use the following method to input the key with value. This should work.

var obj = {};
obj[leaderboardname] = leveldata
var result = server.UpdateUserReadOnlyData({
    PlayFabId: currentPlayerId,
    Data: obj,
    Permission: UserDataPermission.Public
});
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.