question

Kim Strasser avatar image
Kim Strasser asked

How can I create a function that takes UserDataPermission.Public and UserDataPermission.Private?

I want to create a function in Cloud Script that I can use for both UserDataPermission.Public and UserDataPermission.Private. But I get this error message:

"Error": {
      "Message": "JavascriptException",
      "Error": "JavascriptException",
      "StackTrace": "ReferenceError: permission is not defined\n    at handlers.UpdateDataPermissionTest (BFD0A-main.js:39:36)\n    at Object.invokeFunction (Script:116:33)"
    }
handlers.UpdateDataPermissionTest = function (args, context)
{
    var lastdateplayedthislevelkey = "LastDatePlayedTest";
    var now = new Date();
    var currentUTCminute = now.getUTCMinutes();
    var currentUTChour = now.getUTCHours();
    var currentUTCdate = now.getUTCDate();
    var currentUTCmonth = now.getUTCMonth();
    var currentUTCyear = now.getUTCFullYear();
    
    var valuename = {"UTCMinute":currentUTCminute,"UTCHour":currentUTChour,"UTCDate":currentUTCdate,"UTCMonth":currentUTCmonth,"UTCYear":currentUTCyear};
    var valuejson = JSON.stringify(valuename);
       
    var obj = {};
    obj[lastdateplayedthislevelkey] = valuejson
    var permisson = UserDataPermission.Private;
    log.info("User permission: " + permission);
    var updatereadonlydata = UpdateUserDataAndPermission(obj, permisson);
    log.info(updatereadonlydata);
    
    return;
}


function UpdateUserDataAndPermission(keyandvalue, userpermission)
{
    var result = server.UpdateUserData({
           PlayFabId: currentPlayerId,
           Data: keyandvalue,
           Permission : userpermission
        });
        
    if ((result != null) && (result.Error == null))
        return true;
    else
        return false;
}

How can I create a function in Cloud Script that takes UserDataPermission.Public and UserDataPermission.Private?

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

·
Sarah Zhang avatar image
Sarah Zhang answered

Please refer to the API reference of UpdateUserData. UserDataPermission is the type of field Permission, which like object or string[]. Permission’s value would be the “Private” or “Public” string. So you can modify the code as something like this.

...
var permission = "Private";
log.info("User permission: " + permission);
var updatereadonlydata = UpdateUserDataAndPermission(obj, permission);
...
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.