Manually add JS Code

0 favourites
  • 14 posts
From the Asset Store
Add SubRip (SRT) subtitles to your videos in Construct 3
  • I need to manually input some JS code into the c2runtime.cs in order to comply with my customers API.

    What is the best way of doing this? The code is a simple function which will be needed when I send some AJAX calls.

    <img src="" border="0" />


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To make a function to call later use a "start of layout" with the "execute javascript" action in the browser object. You will have to rewrite the first line of your function like this so you can call it later:

    this.getHashFromUrl = function()

    Then you can call it later with another "execute javascript" action like this:


    Be warned that it may not work with a minified export. Also in general it is probably preferred to just make a plugin.

  • Thank you. I haven't looked into making plugins, I might do that first.

    Appreciate the help.

  • You're welcome. On further thought "this" is the only thing that's not minified so it should work with a minified export. You only run into trouble if you try accessing thing that will be minified such as "this.runtime".

  • Gotcha! Thanks.

  • I strongly recommend using the Javascript SDK if you need to execute more than a single line of javascript.

    BTW looks like the Browser object expressions might be able to do what that javascript code does anyway!

  • Oh, good point Ashley, I hand't even thought of that.

  • R0J0hound

    Before I go jumping into the SDK, how do I take my code from above and do what you said? Do I replace all the double quotes with single quotes?

    OK, I think the answer is yes as I don't get any errors.

    Now the next issue is

    <img src="" border="0" />

    Do I use Ajax for this, or should I create functions in code to do these?

    I am really hoping this info will come in handy to others that plan on selling their games to publishers. Getting this all work out will make it much easier in the future. :).

  • Or if anyone else has a clue :)

  • K, I think the answer is yes as I don't get any errors.


    o I use Ajax for this, or should I create functions in code to do these?

    Whichever you can use to get it to work. I'm not too familiar with ajax calls but it may be simpler to use the plugin if there are edge cases it handles. But again I have a knowledge gap about that that you can probably find alot of resources about with google.

  • ...Thinking out loud:

    If it is values you seek from the url, or any other thing that lead a user to your program, and your using a database with web resources on your own host, you could perhaps use a simple php landing page.

    Like, link to your game becomes: (insteead of index.html)

    Have the PHP catch anything you need, from URL variable, to surfer details, to user login details etc, and stuff that in a database with a generated code by php. Then have PHP forward you to your index.html.

    When the game starts perform an ajax request to your server which again generates the code and fetches whatever details you had it store.

  • Thanks to both of you.

    I'm really trying figured out exactly what they are trying to do with the code and just reconstruct it using Construct.

    My issue right now is variables that are created in the Java Script code cannot be accessed by C2, or by other functions that I can see. Recreating what they want in C2 might be the only way.

    Or I need to go the SDK route, if that will even work with what they want.

  • If the client page generates some code in their webpage, cant you use a native javascript ajax post to a php database, and have cs2 retrieve that ?

    Major advantage of using the cs2 ajax is that it is most compatible.

  • Sure, but that is not how they have it setup :). So I am kind of stuck trying to get it to work with their code that they can't alter so it stays uniform per developer.

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