question

Engin Yılmaz avatar image
Engin Yılmaz asked

How Can I Trigger a Server Function With User-Input?

Hello,

Happy new year all. I am new in network gaming and there is an issue that i cant understand the logic. The question is this;

For example I want to make a server authoritative game and in this game I want to trigger a function which is calculating a random number and returning it to user when user clicks a button. How can i write this code in playfab with c#? What i need to write to server side code and what i need to write to client side code to communicate with each other?

This kind of example will be very helpful to me to understand network gaming communicating process. Thank you.

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

I am not sure if your case needs an external server, but for generating an random number, you can simply try to make use of Cloud Script. Cloud script is a powerful feature of PlayFab that can handle most of your server side needs.

  1. Write random number generator in Cloud Script, upload to PlayFab and make it live;
  2. Bind the PlayFabClientAPI.ExecuteCloudScript function with the Button;
  3. Click the button to trigger the function and you can receive generated number in OnSuccessCallback;

You may notice the FunctionParameter in the ExecuteCloudScriptRequest, this is a variable that can be passed to the Cloud script, as a result, you can pass something like random seed for custom random generation.

4 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.

Engin Yılmaz avatar image Engin Yılmaz commented ·

Hello Seth,

I know Cloud Script but i dont want to use it. I want to learn how can i write it in my server executables code and call it with a button click from user side.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Engin Yılmaz commented ·

Implementing a custom external server is already beyond our support scope and this forum is for helping users solve PlayFab related issue. As I have mentioned, your requirement can be fulfilled by Cloud Script, but you can implement a listening port for HTTP requests on your server. Cloud Script is based on V8 JavaScript engine, you can look for official documentation if you are interested.

0 Likes 0 ·
Engin Yılmaz avatar image Engin Yılmaz Seth Du ♦ commented ·

As i know, PlayFab also have servers for deploying our server executables. So there is no need to rent an external server for our server builds. I just want to know which APIs i need to use in client side code to trigger a server builds code for processing a task in PlayFab server.

0 Likes 0 ·
Show more comments

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.