question

Trevor Godley avatar image
Trevor Godley asked

What is the proper way to write Cloudscript to allow the Client to call ListMultiplayerServers

I am trying to write a Cloudscript for the client to call ListMultiplayerServers from the MultiplayerAPI. I have no experience with javascript, so I'm unsure of the proper way to write the Cloudscript function. I am currently wrapping the request on the Client-side in the class ListMultiplayerServersRequest, and passing that as the function args. From my understanding, I should validate the args Server-side and then make the API call. Here is my attempt, I would appreciate any and all feedback:

handlers.ListServers = function(args){
    if(!args || !args instanceof multiplayer.ListMultiplayerServersRequest){return};
    var response = multiplayer.ListMultiplayerServers(args);
    return{ response: response};
}
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

·
Gosen Gao avatar image
Gosen Gao answered

Just make sure that before you make the call, the CloudScript has got every necessary parameters and the parameters have been validated. That would be alright.

In the common scenario, we wrap the request in the CloudScript with parameters of args. What you did to wrap the request is also a right way.

But this “multiplayer.ListMultiplayerServersRequest” is undefined in the CloudScript. I suggest you to validate the parameters one by one.

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.