question

joeypc6 avatar image
joeypc6 asked

unity - playfab cloudscript

So I Had This

handlers.GetOthersInv = function (args,ID){
    var inventory = server.GetUserInventory({ PlayFabId: args.ID});
    var Mystring = null;
     for (var i = 0; i < inventory.Inventory.length; i++) {
       if (inventory.Inventory[i].ItemClass == "Inventory"){
        Mystring += "#" + inventory.Inventory[i].DisplayName + " x" + inventory.Inventory[i].RemainingUses + "#";
       }
    }
   return { messageValue: Mystring };
}


And I Want To Get The message out In Unity

So I have this

public void LoadIslandInventory()
	{
		Dictionary<string, string> data = new Dictionary<string, string>();


		data.Add("ID", PlayfabLogin.Instance.pfid);


		PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest
		{
			FunctionName = "GetOthersInv",
			FunctionParameter = data

		},
			result =>
			{


				Debug.Log(result.FunctionResult);


			}
			,
			error =>
			{
				Debug.Log("Cloud Script call failed");
				Debug.Log(error.GenerateErrorReport());
			});
	}

And I Get This Log

System.Collections.Generic.List`1[PlayFab.ClientModels.LogStatement]
UnityEngine.Debug:Log(Object)
Help!!!!
apisCloudScript
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

·
JayZuo avatar image
JayZuo answered

Hi joeypc6,

In Cloud Script, any object you return is serialized as json, and returned to the caller. So instead of logging the whole `FunctionResult`, you can try like the following to get your returned string.

result =>
{
    //Debug.Log(result.FunctionResult);
    JsonObject jsonResult = (JsonObject)result.FunctionResult;
    object messageValue;
    jsonResult.TryGetValue("messageValue", out messageValue); 
    Debug.Log((string)messageValue);
},
1 comment
10 |1200

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

joeypc6 avatar image joeypc6 commented ·

Thanks Worked But U Need

using PlayFab.Json;
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.