Is it possible to get the new value of the key "Country" in the client code if I use "return server.GetUserReadOnlyData({PlayFabID: currentPlayerId, Keys: "Country"});" in my cloudScript?
Console.WriteLine(result.Result.???);
I want to get the new value of the key "Country" in Result. Is this possible?
Or is it necessary to call "var resultprofile = await PlayFabServerAPI.GetUserReadOnlyDataAsync(new PlayFab.ServerModels.GetUserDataRequest()" to get the new value of the key "Country" in the client code?
Client code:
private async Task UpdateCountry() { var result = await PlayFabClientAPI.ExecuteCloudScriptAsync(new ExecuteCloudScriptRequest() { FunctionName = "UpdateCountryReadOnlyData", FunctionParameter = new { PlayerDataCountry = "Germany" }, GeneratePlayStreamEvent = true }); if (result.Error != null) Console.WriteLine(result.Error.Error.ToString()); else { if (result.Result.Logs.Count() > 0) Console.WriteLine(result.Result.Logs[0].Message); else Console.WriteLine("Country: " + result.Result.???); } }
CloudScript:
handlers.UpdateCountryReadOnlyData = function (args, context) { var NewCountry = args.PlayerDataCountry; var resultdata = server.GetUserReadOnlyData({PlayFabId: currentPlayerId, Keys: "Country"}); // first search for the current country info var CurrentCountry = ""; if(resultdata.Data.hasOwnProperty("Country")){ // if country info already exists in readonly data if ((resultdata.Data.Country.Value != null) && (resultdata.Data.Country.Value != "")){ // make sure the value is not null or "" CurrentCountry = resultdata.Data.Country.Value; log.info("Already has country info, current country is:" + CurrentCountry.toString()); // if country value already exists, notify the client that Country info already been set } else{ // if country value is null or "", set the Country value server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Data: { "Country": NewCountry } }); } } else{// if country hasn't been set yet, set it for the user server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Data: { "Country": NewCountry } }); } return server.GetUserReadOnlyData({PlayFabID: currentPlayerId, Keys: "Country"}); // return the current country info to the clients. }