Jump to content

Playfab Plugin?


greencoder
 Share

Recommended Posts

@greencoder

I just added support for loading external JavaScript files with addAsset function. Now you can easily load all the PlayFab libraries that you need.

Take a look at the PlayFab JavaScript guide: https://api.playfab.com/docs/getting-started/javascript-getting-started

Example:

game.module(
    'game.main'
)
.body(function() {

game.addAsset('https://download.playfab.com/PlayFabClientApi.js');

game.createScene('Main', {
    init: function() {
        var loginRequest = {
            TitleId: 'myTitleId',
            CustomId: 'myCustomId',
            CreateAccount: true
        };
        
        // Now you can access PlayFabClientSDK object
        PlayFabClientSDK.LoginWithCustomID(loginRequest, function(result, error) {
            if (!error) {
                console.log('Congratulations, you made your first successful API call!');
            }
            else {
                console.log(error);
            }
        });
    }
});

});

Remember to update your game engine to latest 2.6.0 version.

Let me know if you have any issues.

Link to comment
Share on other sites

  • 1 year later...
  • 5 weeks later...

An update about this thread, to sum it up, thanks @enpu, it works. For some reason, my PC's Panda IDE was an old version and it might have caused the issue. So here are the steps

  1. Download latest panda IDE
  2. Update the engine to the latest in your project
  3. Download PlayFabClientApi.js from https://download.playfab.com/PlayFabClientApi.js into the media folder 
  4. Add game.addAsset('PlayFabClientApi.js') to your game.main
  5. Add the following snippet to test whether it works (I used it in init of game.main), ideally when you run this in the IDE or the browser, a player will be created on PlayFab 
     
    var loginRequest = {
     TitleId: '<your game ID>',
     CustomId: <custom ID>,
     CreateAccount: true
    };
    PlayFabClientSDK.LoginWithCustomID(loginRequest, function(result, error) {
     if (!error) { console.log('PF ID: ' + result.data.PlayFabId); }
     else { console.log(error);}
    });

 

As a next step, I prefer to make PlayFabClientApi.js into a plugin, like the instantgames plugin and load the script dynamically and not bundle it with the package. I shall keep this thread updated if the plugin is a success, or maybe drop if off in the plugins sub forum. 

Once again, thanks @enpu!

@Stephan, there you go, done! Time to start with the game, yay! 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...