Using PlayFab Service in Construct 2

3

Index

Attached Files

The following files have been attached to this tutorial:

.capx

c2-playfab-example.capx

Download now 179.69 KB

Stats

5,534 visits, 10,371 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 19 May, 2018. Last updated 19 Feb, 2019

Step 3 - Prepare your project

Let's create a blank project. Then import previous js file into your project.

Now let's add the following plugin into your project :

- Browser

- Function

Also add the following object into your layout :

- 1 Input Text Box

- 1 Button

- 2 Text

Place it the way you like.

Step 4 - Configuring project

Now let's create a new Event Sheet, name it "PlayFab" then add 3 global variables :

Set the TITLE_ID variable with your Game Title ID from PlayFab dashboard.

Write a On Start Layout condition and add Browser->Execute Javascript as an action.

Copy these line as the value :

    "var js = document.createElement('script');
    js.type = 'text/javascript'; 
    js.src = 'playfabclientapi.js';
    document.body.appendChild(js);"
   

Then create a new Function, name it LoginWithCustomId , also add Browser->Execute Javascript as an action.

Copy these line as the value :

    " var loginRequest = {
    	TitleId: '"&TITLE_ID&"',
    	CustomId: '"&Function.Param(0)&"',
    	CreateAccount: true
    };
    var LoginCallback = function (result, error) {
    	if (result !== null) {
    		c2_callFunction('OnLoginWithCustomID',['success',result.data.PlayFabId,result.data.SessionTicket,'"&Function.Param(0)&"']);
    	} else if (error !== null) {
    		c2_callFunction('OnLoginWithCustomID',['error',PlayFab.GenerateErrorReport(error)]);
    	}
    }; PlayFabClientSDK.LoginWithCustomID(loginRequest, LoginCallback); "
   

For the callback function (so we know whether the login success or fail), Create a new function named OnLoginWithCustomID, there are 2 condition for parameter 0 : "success" or "error". You can create these event to notify the login process :

Now let's move to the layout's event sheet. Include the "PlayFab" event sheet.

Create an event to indicate user's click on the button. Add Function->Call Function as an action. Set the parameter as below :

The last, let's set both variable Text UI to the variable

Let's run your project and see if it's work.

It's so simple isn't it?

  • 3 Comments

  • Order by
Want to leave a comment? Login or Register an account!