Listen for javascript?

0 favourites
  • 10 posts
  • Hi,

    I'm working on a project for a client and I have implemented google video ads to run at a certain point with the browser object executing a javascript.

    I know that when the ad is over or skipped, the script calls a function 'adsCompleted()' - so my question is how would I get construct to 'hear' that and I can then un pause the game etc..

    any help would be appreciated. Thank you!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [quote:2rbl6g2z]Check out these links:

    https://www.scirra.com/tutorials/1078/b ... -js-and-c2

    site-calls-an-action-within-the-game_t115902

    Hey thanks for that, I had a look and it seemed to be referring to C2 in a lot of cases and calling out.

    I read about making the function inside construct by the same name as the javascript call, so I did that checked when it should have triggered it - but seemingly nothing happened

    I'd like to know if that's the basics of what I need to do though, just name a function inside construct thats the same as 'adsCompleted()' - or do I need to ad something else to the parameters of the function inside construct 3. Thanks again.

  • Oh, sorry I didn't realize this post was in C3 forum.

    I think you should be able to use "c3_callFunction" to call back your C3 function.

    It could be something like this:

    In your JS file:
    adsCompleted = function() { 
            c3_callFunction("myAdsCompleted");
    }
    
    In the event sheet:
    Function "myAdsCompleted" -> Set variable gamePaused=1
    ....
    [/code:316tm13t]
    
    See an example in this comment:
    
    (as R0J0hound mentioned, you'll have to rename "c2_callFunction" to "c3_callFunction")
  • Ah great thanks for clarifying there.

    Just one other thing then, if I don't have access to write inside the advert launching javascript .js file, would I still be able to add that just in the index.html file as a script and it know what to do?

    as in this section

    adsCompleted = function() { 
            c2_callFunction("myAdsCompleted");
    }[/code:15rz3lyb]
    
    or do i need to also reference the source .js file in there somewhere too?
  • Sorry, I don't know.. I'm not a big specialist in JS.

    Are you saying you can't modify the JS file with that adsCompleted() function?

    I thought it was supposed to be user-defined function?

  • So I found out they are still using c2_callFunction (for legacy reasons)

    but even trying c2 I see

    [quote:2itvq2ce]c2_callFunction is not defined

    I checked and double checked the function object is in my project, and I made a function with the same name trigger a scene change but still seeing that error

  • You could try the javascript addon.

  • You could try the javascript addon.

    hmm is that the plugin SDK or something else?

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