[Plugin] JavaScript (C2 and C3)

2 favourites
From the Asset Store
A cool way for kids to write and practice English Alphabets
  • Hey!

    JS.AliasValue is a Construct expression. It only returns Construct basic types: number or string. It can't return arrays. Construct doesn't understand this type of variables.

    Thus, JS.AliasValue( "wavePoints" ) returns 0, so you're calling function "updateWavePoints" with parameter "0".

    Also the thing that you're doing is very strange. You have both "updateWavePoints" function and "wavePoints" array in javascript, but instead of calling the function in javascript code, you're trying to call it from Construct. That is wrong on so many levels.

    If you're using Javascript Plugin you're supposed to either call javascript functions with parameters from Construct, or do Construct stuff using data from javascript. Using plugin to call javascript functions that operate on javascript data that was taken from javascript to Construst and translated back to javascript, — is weird and ineffective.

    Hi, i've a problem with arrays. I've two functions in my js, the first one return an array as result, and it works correctly. Then i need to call the second one passing the array (stored in an alias) as parameter but it seems to not working. What i'm wrong!?

    As you can see, "wavePoints" is an array, and i would like to pass to "updateWavePoints" function.

  • Is a port from the plugin to the new C3-Runtime possible ? :)

    The new version wit C3-Runtime support is out!

    construct.net/make-games/addons/1/javascript

  • valerypopoff Thank you for the port! Very useful :)

  • Hey guys! I'm on Patreon now. So if you ever wanted to support me, this is about time:

    Support me on Patreon

  • Great Addon!

    Curious how to implement google's ExitApi.js for interactive HTML5 ads.

    Normally you Include the following script in your HTML <head> tag:

    <scripttype="text/javascript" src=" tpc.googlesyndication.com/pagead/gadgets/html5/api/exitapi.js "></script>

    Then make the following JavaScript call to enable a final URL: ExitApi.exit()

    - For example, send a consumer to the final URL, using a standard anchor:

    - <a onclick="ExitApi.exit()">Learn more</a>

    Rather than include a link to the ExitApi script I included it as a .js file and then attempted to call the function on touch tap.

    The ExitApi.js file is a global "function()" - I modified it to be: "function exitScript()"

    It doesn't seem to work. Wondering if you or anyone else has experience in getting this to work.

    Thanks in advance!

    Chris

  • Hey, cheers!

    Well I've never used ExitApi.js and I have no idea what that is. But there's no reason to believe that there's something about it that makes it work in web pages but doesn't allow it to work in a Construct game with my plugin.

    Normally you Include the following script in your HTML <head> tag

    You can do the same with javascript by accessing DOM elements.

    I don't understand what you mean by "I modified it to be: "function exitScript()". What did you modify? Why would you do this?

    It doesn't seem to work.

    Why do you think it's not working? What is the expected behavior? Did you look in the console? Does it show any errors?

    Great Addon!

    Curious how to implement google's ExitApi.js for interactive HTML5 ads.

    Normally you Include the following script in your HTML <head> tag:

    <scripttype="text/javascript" src=" tpc.googlesyndication.com/pagead/gadgets/html5/api/exitapi.js "></script>

    Then make the following JavaScript call to enable a final URL: ExitApi.exit()

    - For example, send a consumer to the final URL, using a standard anchor:

    - <a onclick="ExitApi.exit()">Learn more</a>

    Rather than include a link to the ExitApi script I included it as a .js file and then attempted to call the function on touch tap.

    The ExitApi.js file is a global "function()" - I modified it to be: "function exitScript()"

    It doesn't seem to work. Wondering if you or anyone else has experience in getting this to work.

    Thanks in advance!

    Chris

  • Hey! Thanks for the response. I apologize for my lack of information.

    I've never used ExitApi.js

    The exitapi.js script is essentially included with an interactive / playable advert that allows for a specific button to be clickable and send a user to a desired URL - Without it the entire advert / playable ad becomes clickable - breaking any further interaction.

    I don't understand what you mean by "I modified it to be: "function exitScript()". What did you modify? Why would you do this?

    The reason I did this is because the script as is is looks like this:

    	(function() {
     var a = function() {
     this.exit = this.b;
     this.close = this.close;
     this.delayCloseButton = this.a
     };
     a.prototype.b = function() {
     window.open("http://adwords-displayads.googleusercontent.com/da/b/html5UploadAd.html", "_blank")
     };
     a.prototype.close = function() {
     window.console && window.console.log("Exit API: Close requested.")
     };
     a.prototype.a = function(e) {
     e = Math.min(e, 5);
     window.console && window.console.log("Exit API: Close Button will not appear for " + e + " seconds.")
     };
     var b = new a,
     c = ["ExitApi"],
     d = this;
     c[0] in d || !d.execScript || d.execScript("var " + c[0]);
     for (var f; c.length && (f = c.shift());) c.length || void 0 === b ? d = d[f] && d[f] !== Object.prototype[f] ? d[f] : d[f] = {} : d[f] = b;
    }).call(this);
    

    In Construct I trigger calling the script with a touch event - I'm assuming I have to name said function in order to call it??

    So I modified it by changing the first line so I have a named function to call.

    (function exitScript() {

    In the console I get this error :

    ValerypopoffJS plugin: Error in 'Call function' action

    ---------------------

    JS code: exitScript()

    ---------------------

    exitScript is undefined

    I greatly appreciate your help!

  • In javascript

    (function(){ ... })()
    

    or

    (function(){ ... }).call(this)
    

    is a self-executing anonymous function. You do this if you want to hide variables from the parent namespace. All the code within the function is contained in the private scope of the function, meaning it can't be accessed from outside the function, making it private.

    Giving this function a name doesn't change anything. It's not accessible. No wonder console says "exitScript is undefined".

    So, the code of ExitApi.js is self-executable. You don't have to do anything to call it. When you add this script to a page, it calls itself.

    If you properly added this script to your page (which we're not sure of. can you give me a project file?), everything should work fine. If you don't see a desirable result, it has nothing to do with the plugin. Most certainly it has something to do with you not completely understanding how it works: api-wise or even javascript-wise.

    > I don't understand what you mean by "I modified it to be: "function exitScript()". What did you modify? Why would you do this?

    The reason I did this is because the script as is is looks like this:

    > 	(function() {
    var a = function() {
    this.exit = this.b;
    this.close = this.close;
    this.delayCloseButton = this.a
    };
    a.prototype.b = function() {
    window.open("http://adwords-displayads.googleusercontent.com/da/b/html5UploadAd.html", "_blank")
    };
    a.prototype.close = function() {
    window.console && window.console.log("Exit API: Close requested.")
    };
    a.prototype.a = function(e) {
    e = Math.min(e, 5);
    window.console && window.console.log("Exit API: Close Button will not appear for " + e + " seconds.")
    };
    var b = new a,
    c = ["ExitApi"],
    d = this;
    c[0] in d || !d.execScript || d.execScript("var " + c[0]);
    for (var f; c.length && (f = c.shift());) c.length || void 0 === b ? d = d[f] && d[f] !== Object.prototype[f] ? d[f] : d[f] = {} : d[f] = b;
    }).call(this);
    

  • Thank you. I am rather new to javascript. I apologize if it came off as I was saying your plugin was the issue. That is not the case, nor do I feel that it is. This is a result of my lack of understanding.

    So, the code of ExitApi.js is self-executable. You don't have to do anything to call it. When you add this script to a page, it calls itself.

    Based on the instructions provided by google - it seems an onclick event is required to call the ExitApi.exit() URL - I realize now based on your explanation that I am approaching this wrong. I am calling an anonymous function, when I should be calling ExitApi.exit() instead of the actual script - exitapi.js - it's self.

    Instructions:

    Include the following script in your HTML <head> tag: <scripttype="text/javascript" src="https://tpc.googlesyndication.com/pagead/gadgets/html5/api/exitapi.js"> </script>

    Then make the following JavaScript call to enable your final URL: ExitApi.exit()

    • For example, send a consumer to the final URL, using a standard anchor:
    • <a onclick="ExitApi.exit()">Learn more</a>

    I'm going to give it another go - I don't want to post my project file publicly so I will message you directly. Again, I really appreciate your explanation and help. My goal is to learn more and obtain an understanding of javascipt. I will be donating to your patreon.

  • valerypopoff

    Thanks again for your explanation!

    I got it to work as intended :)

  • Supercool! Glad if I helped a little. Sorry for my douchebaggy tone)

    valerypopoff

    Thanks again for your explanation!

    I got it to work as intended :)

  • No need to be sorry - I came off as a "can you do this for me?" noob. lol

  • Hey guys! It's been a long time since the basic functionality of JS plugin was introduced. I've polished it since then but if I remember it right, no one really requested any additional functionality. If you wanted to make a suggestion, it's about time.

  • Hey there.

    I am trying to integrate a library. I don't know anything about Construct unfortunately.

    The lib is here:

    wickeyware.github.io/wickeyappstore

    In the index.html I need something like this

    <head>

    <!-- WickeyAppStore css -->

    <link rel="stylesheet" href="elements/styles.css">

    </head>

    <body>

    <wickey-appstore></wickey-appstore>

    <script type="text/javascript" src="elements/wickeyappstore.js"></script>

    </body>

    This is the simplest case integration. Can I do that with your plugin?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If this is a js-library and it works if you add it to the regular web page, then yes. You can do this with js plugin too.

    Hey there.

    I am trying to integrate a library. I don't know anything about Construct unfortunately.

    The lib is here:

    https://wickeyware.github.io/wickeyappstore/

    In the index.html I need something like this

    <head>

    <!-- WickeyAppStore css -->

    <link rel="stylesheet" href="elements/styles.css">

    </head>

    <body>

    <wickey-appstore></wickey-appstore>

    <script type="text/javascript" src="elements/wickeyappstore.js"></script>

    </body>

    This is the simplest case integration. Can I do that with your plugin?

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