question

sobetech avatar image
sobetech asked

How to parse Server List String in Unity.

Hello all I'm trying to use cloud script to ultimately return a list of server summaries I setup on PlayFab. I want to setup up a UI and connect through mirror after picking a server. It returns a long unformatted string. How would i just turn this string into the multiplayserverlist it returns? Thanks in advanced!

Here is my could call:

handlers.listservers= function (args, context) {
    if (args && args.reg)
        reg = args.reg;
    var request = {
  "BuildId": "9d3bb139-185d-4f0e-aed2-c55fdc2a0799",
  "Region": reg
};
    var result = multiplayer.ListMultiplayerServers(request);
    
    return result;
}
unity3dmultiplayer
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

You can convert the JSON object returned from the ExecuteEntityCloudScriptRequest to the object whose type is PlayFab.MultiplayerModels.ListMultiplayerServersResponse, then use foreach method to list all items of ServerList.MultiplayerServerSummaries. The code could be something like this.

 private void OnSuccess(LoginResult obj)
    {
        object para = new { reg = "EastUS" };
        PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new PlayFab.CloudScriptModels.ExecuteEntityCloudScriptRequest { FunctionName = "listservers", FunctionParameter = new { reg = "EastUS" } }, OnGetServerListSuccess, OnFail);
    }


    private void OnGetServerListSuccess(PlayFab.CloudScriptModels.ExecuteCloudScriptResult result)
    {
        var serializer = PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer);
        var ServerList = serializer.DeserializeObject<PlayFab.MultiplayerModels.ListMultiplayerServersResponse>(result.FunctionResult.ToString());
        foreach (var item in ServerList.MultiplayerServerSummaries)
        {
            Debug.Log(item.ServerId);
        }
    }

There are some other relevant discussions on this topic.

https://community.playfab.com/questions/14898/get-return-value-from-cloud-script.html

https://community.playfab.com/questions/4521/executecloudscript-functionresult-frustration.html

https://community.playfab.com/questions/12060/cloudscript-return-issue.html

https://community.playfab.com/questions/5276/what-object-type-does-cloudscript-return-in-its-fu.html

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.