How to Return PlayFab Callback Results to Event Sheet

0 favourites
  • 7 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • Hello all - new to Construct 3 but have been enjoying the engine so far. I was working through some examples and successfully used the PlayFab javascript SDK for LoginWithCustomID. What I am not sure however, is what the best way within construct to pass the results from a javascript file back into event sheets.

    My initial thought was to use the runtime.callFunction to an eventsheet function that accepted the results as an argument but runtime is not defined. The line below generates a promise but I am not sure how best to await / get the results back from the call back:

    PlayFabClientSDK.LoginWithCustomID(loginRequest, LoginCallback)
    

    full .js example (this is called by an event sheet function and in dev tools I can see the results, just don't know how to appropriately return it):

    function DoExampleLoginWithCustomID(f_Title_ID,f_Custom_ID){
     PlayFab.settings.titleId = f_Title_ID;
     var loginRequest = {
     // Currently, you need to look up the correct format for this object in the API-docs:
     // https://api.playfab.com/documentation/Client/method/LoginWithCustomID
     TitleId: PlayFab.settings.titleId,
     CustomId: f_Custom_ID,
     CreateAccount: true
     };
    
    
    	PlayFabClientSDK.LoginWithCustomID(loginRequest, LoginCallback)
    	
    }
    
    var LoginCallback = function (result, error) {
     if (result !== null) {
    		console.log("It worked! Log");
    		
    		return result //this doesn't work
    		
     } else if (error !== null) {
    		console.log("It didn't worked! Log");
     return "Something went wrong with your first API call.\n" +
     "Here's some debug information:\n" +
     PlayFab.GenerateErrorReport(error);
     }
    }
    

    Thanks for any help you can offer!

    Tagged:

  • One way to do this:

    - On your JS callback fcn have it call a c3 event based function with the result as a parameter. Then you can assign that result to whatever you want in c3 events (e.g. a C3 global or do something with it in events.)

    - in JS do the following to call C3 function defined in events (instead of doing 'return result'.)

  • Thanks for the quick reply!

    I was attempting to implement something similar to this. I have what is needed on the event sheet but what I run into is that "runtime" is not defined. I am not positive on what the best way is to ensure it is defined, any suggestions?

    Below is current callback function:

    var LoginCallback = function (result, error) {
     if (result !== null) {
    		console.log("It worked! Log");
    		var sessionTicket = result.data.SessionTicket;
    		runtime.callFunction("LoginWithCustomID_Results",sessionTicket)
    		//return "TESTING" //this doesn't work
     } else if (error !== null) {
    		console.log("It didn't worked! Log");
     return "Something went wrong with your first API call.\n" +
     "Here's some debug information:\n" +
     PlayFab.GenerateErrorReport(error);
     }
    }
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Try this (I will also test):

    Add this to an on startup script event:

    globalThis.myIruntime = runtime
    

    Then do this in your call back:

    myIruntime.callFunction("LoginWithCustomID_Results",sessionTicket)
    

    If you are on the unofficial Construct Community Discord we can discuss over there too in realtime...

  • Awesome!

    Thank you so much! worked liked a charm. I went down such a worm hole looking for solutions after banging my head on this.

    Cheers

  • Also, just so you know there is a paid plugin that includes Playfab functions:

    chadorirebornxd.itch.io/construct-master-collection

  • Also, just so you know there is a paid plugin that includes Playfab functions:

    https://chadorirebornxd.itch.io/construct-master-collection

    very expensive lol

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)