RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] Order Allow,Deny Deny from all {"id":3601,"date":"2020-01-25T06:29:39","date_gmt":"2020-01-25T06:29:39","guid":{"rendered":"https:\/\/www.infogamerhub.com\/?p=3601"},"modified":"2020-09-02T15:09:06","modified_gmt":"2020-09-02T20:09:06","slug":"how-to-use-playfab-in-unity-3d-cloud-scripts-lesson-5","status":"publish","type":"post","link":"https:\/\/www.infogamerhub.com\/how-to-use-playfab-in-unity-3d-cloud-scripts-lesson-5\/","title":{"rendered":"How to Use PlayFab in Unity 3D: Cloud Scripts (Lesson 5)"},"content":{"rendered":"\n

Learn how to Use Cloud Scripts<\/h2>\n\n\n\n

In this lesson on how to use PlayFab in Unity 3D, we will teach you more about Player Statistics. In our last video, we show you how to get and set player statistics from the client application but as I said in the last video, it can be a bad practice to send updates to the player statistics from the client-side. We will fix this by showing you how to send a request to run a server-side code hosted by PlayFab’s cloud scripts.<\/p>\n\n\n\n

Documentation: https:\/\/api.playfab.com\/docs\/tutorials\/landing-automation\/writing-custom-cloud-script<\/a><\/p>\n\n\n\n

SUBSCRIBE for regular Video Game making videos:
https:\/\/www.youtube.com\/channel\/UCyoayn_uVt2I55ZCUuBVRcQ?sub_confirmation=1<\/a><\/p>\n\n\n\n

About Player Statistics<\/h3>\n\n\n\n

For getting started we want to go to our PlayFab dashboard. We will then want to click out our current project. We will then select Players and then we will select one of our player accounts. From here we need to click on statistics. In the statistics page, it is important to know that each statistic you add to a player account is then permanently associated with that player. The values of the stats can be changed by the key cannot. It is also important to know that you can add new stats just by typing in a new key in the statistics page and click Save Statistics. <\/p>\n\n\n\n

Disabling Client POSTing<\/h3>\n\n\n\n

Now will go to the Setting – API Features and then we will uncheck the box we checked in the last lesson that says “Allow clients to post player statistics” and then we will click save.<\/p>\n\n\n\n

Cloud Scripts – Server Code<\/h3>\n\n\n\n

Now we need to go to the Automation section which will take us to what is called Cloud Scripts. Cloud Scripts are server-side code written in JavaScript and hosted by PlayFab for free. In the default cloud script, you will see a function called MakeAPICall. This function currently will set one default statistic. We will customize this function so that it will receive value from our game and set the statistics we need for our game. Once you have this function created, you will then need to save and deploy this revision. <\/p>\n\n\n\n

Client Request to Run Server Function<\/h3>\n\n\n\n

Now, it is time to go to our Unity project and open our PlayFabController script. Is side our script we need to create new functions that will request PlayFab to run our new Cloud Script function. There are some example functions written in the documentation I have to add up above. We will paste those functions into our code and then customize them so they will send the correct parameters to the correct JavaScript function.<\/p>\n\n\n\n

Testing your Project<\/h3>\n\n\n\n

It is now time to test our project. We will save our script and go back to Unity. We then need to reassign the function that is paired to our Update Stats button. It should now be the new function we just created. We can then play our game. We then need to select our PlayFabController object and change the stats variables we have there. Then when we click the Update Stats button we should then be able to see the values of our player statistics change in our dashboard. <\/p>\n\n\n\n

\n