question

Riccardo Iengo avatar image
Riccardo Iengo asked

Get multiple player data in one cloud script

Hi!

I need to call server.GetUserData and server.GetUserReadOnlyData within the same function in the cloud script. Is it possible to do this? If yes, can you provide me an example of how should work?

handlers.GetMyData = function (args, context)
{
    var data = args.Value;
    
    var playerData = server.GetUserData({
        PlayFabId: currentPlayerId,
        Keys: [data]
    });
    
    var data2 = args.Value2;
    
    var playerInfo = server.GetUserReadOnlyData({
        PlayFabId: currentPlayerId,
        Keys: [data2]
    });
    
    return {"Value": playerData.Data[data].Value, 
    "Value2": playerInfo.Data[data2].Value2}
}

I did this but it's not working! Thanksss

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

Yes, it’s possible to get the Player Data and the Player Read-Only Data in one CloudScript function. Your code can work fine after fixing the typo on the line 18. Since the “Value” is the general sub-property name of the object Data, you shouldn’t use the “Value2” to instead it. You can modify the content you want to return as something like this. Besides, please note the Player Data and Read-Only Player Data can both be read by the clients directly. If you want the data to be unreadable to clients and only readable to servers, you need to store them in the Internal Player Data.

return
{"Value": playerData.Data[data].Value, "Value2":
playerInfo.Data[data2].Value}
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.