How to Customize Construct 2 Code

0 favourites
  • 10 posts
From the Asset Store
Project File of my C3 Tutorial Customized DropDown List
  • Hi Everyone, I Need Help in customizing Construct-2 Exported Code.

    I made a game for client, He wants to call a function in Index.html to give alert of total-points when user clicks a Specific Button ("Done Button" in Game)

    Here is Game Link ....

    dl.dropboxusercontent.com/u/196969557/Betty_Bellows%20V2.5/index.html

    Right Now When you click on Done, it calls browser alert message.

    But My Client wants to Implement this in Index.html.

    I Need help how I can call this function in Index.html when user clicks on done button, & Access ("TotalPoints" Global Variable in C2Project)

    /**** (I Have less Knowledge about Coding)

    index.html

    <script>

    function update_points(points)

    {

    alert(points);

    }

    </script> ***/

  • The Browser object has an alert action already.

  • I know that Browser has a alert action. But When I export it, Browser alert can not be accessed due to C2-Export Mechanism. My Client wants to call API in this function. I See nothing in "runtime File" which can be understood.

  • If I understand this correctly, using the execute javascript action of the browser object should do the trick. Have you tried that already?

  • c2runtime.js

    at the very top or bottom(before or after C2 closure) insert the API code chunk. Make sure it's part of the window.[foo name space]

    then in C2

    Browser.execJS( api.function_name )

    You will need to insert this custom JS code into the c2runtime every time.

  • c2runtime.js

    at the very top or bottom(before or after C2 closure) insert the API code chunk. Make sure it's part of the window.[foo name space]

    then in C2

    Browser.execJS( api.function_name )

    You will need to insert this custom JS code into the c2runtime every time.

    Any particular reason why you suggest to put the code in the runtime file?

    Having it in the index.html should work just as well. Also you simply could keep a separate index file in the export folder without the need to always inject the script anew after exporting.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can also create a simple plugin with no functions. Which sole job is to insert the custom api into window.foo name space. Then he wouldn't even need to modify anything else. So why not that. Even makes it easier in the long run. Also some wrappers don't even use the index.html.

    I can't say he is using CJS, more than likely it's just for a web browser. But if say it were CJS. Then putting the modifcation in index.html would have no effect as index.html isn't being used.

  • You can also create a simple plugin with no functions. Which sole job is to insert the custom api into window.foo name space. Then he wouldn't even need to modify anything else. So why not that. Even makes it easier in the long run. Also some wrappers don't even use the index.html.

    I can't say he is using CJS, more than likely it's just for a web browser. But if say it were CJS. Then putting the modifcation in index.html would have no effect as index.html isn't being used.

    Ah, I see where you're coming from. I suppose you could also easily include an external js script by adding the CallJS plugin, which has a property to do so.

  • Executing strings with the Browser object is an ugly hack. If you want to do it properly, use the Javascript SDK.

  • Executing strings with the Browser object is an ugly hack. If you want to do it properly, use the Javascript SDK.

    Can't say I'm that much into cosmetics. So I wouldn't really care if something was "ugly", as long as it worked of course. <img src="smileys/smiley1.gif" border="0" align="middle">

    But seriously it seems to me that making a plugin just to use one javascript method or two is a little bit of an overkill.

    Would you care to elaborate briefly why you deem it a bad idea to use the execute javascript action/ expression of the browser object? Are there possible issues people don't usually consider?

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