question

Jacob Grodman avatar image
Jacob Grodman asked

Cloudscript CreateSharedGroup return

So I'm very new to cloudscript and javascript, so there are probably issues with this code, but I can't get it to return a value. I've tweaked every single line.

The scripting API for CreateSharedGroup says that it has a string return value, but I can't get a this function to return anything but null or a null reference exception.

I really just need a straightforward example of server.CreateSharedGroup, but I can't find one.

public void CreateMatchSharedGroup()
    {
        PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
        {
            FunctionName = "CreateSGD",
            FunctionParameter = false
        },
        OnGroupCreationSuccess, CreateSGDError);
    }


	// Create SGD for new match
	handlers.CreateSGD = function (args){
	    var createdGame = server.CreateSharedGroup();
	    return createdGame;
	};

    public void OnGroupCreationSuccess(ExecuteCloudScriptResult result)
    {
   	var data = JSON.Parse(result.FunctionResult.ToString());
    	print(data);
    }

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

·
Seth Du avatar image
Seth Du answered

The CreateSGD function you wrote will produce this error: (I am using RESTful testing tool Postman)

"Error": {
    "Error": "JavascriptException",
    "Message": "JavascriptException",
    "StackTrace": "Error: The best overloaded method match for 'PlayFab.LogicServer.Source.PlayFabAPI.api_request(string, string, string)' has some invalid arguments\n    at HostDelegate.<anonymous> (<anonymous>)\n    at Object.server_request (Script:153:41)\n    at Object.server.CreateSharedGroup (Script:509:74)\n    at handlers.CreateSGD (5AFBD-main.js:35:31)\n    at Object.invokeFunction (Script:116:33)"
}

The root cause is there is no request input for CreateSharedGroup API call on line14:

var createdGame = server.CreateSharedGroup();

Each PlayFab API will require a proper request, you may refer to this API document to see how to define one:

https://docs.microsoft.com/en-us/rest/api/playfab/server/shared-group-data/createsharedgroup

A correction would be:

handlers.CreateSGD = function (args){
           var createdGame = server.CreateSharedGroup({
              SharedGroupId: "test"  //input your customized ID
           });
           return createdGame;
       };
2 comments
10 |1200

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

Jacob Grodman avatar image Jacob Grodman commented ·

Hi Seth, thanks for the response.

That was what I assumed the issue was, but the documentation says that the only required input is a Shared Group ID, and in the same sentence says that a random one will be assigned if one isn't specified. Client-side CreateSharedGroup works without providing a Shared Group ID. Is that just not the case with the server-side?

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ Jacob Grodman commented ·

Hi @Jacob Grodman,

Seth was right, The server function requires a request input, which can also be an empty object.

server.CreateSharedGroup({});<br>

I have tested it, the code above also works. And it will create a shared group with random id.

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.