How to Return PlayFab Callback Results to Event Sheet

  • 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:
     // 

    api.playfab.com/documentation/Client/method/LoginWithCustomID [/p] TitleId: PlayFab.settings.titleId, [/p] CustomId: f_Custom_ID, [/p] CreateAccount: true [/p] }; [/p] [/p] [/p] PlayFabClientSDK.LoginWithCustomID(loginRequest, LoginCallback) [/p] [/p] } [/p] [/p] var LoginCallback = function (result, error) { [/p] if (result !== null) { [/p] console.log("It worked! Log"); [/p] [/p] return result //this doesn't work [/p] [/p] } else if (error !== null) { [/p] console.log("It didn't worked! Log"); [/p] return "Something went wrong with your first API call.\n" + [/p] "Here's some debug information:\n" + [/p] PlayFab.GenerateErrorReport(error); [/p] } [/p] } [/p]

    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'.)

    runtime.callFunction(name, ...params)
    
  • 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 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)