Functions for Publishers

0 favourites
  • 7 posts
From the Asset Store
About 900+ game portals: 400 e-mails, 514 contact/submit forms (last update: 2022, October, +275 contacts)
  • Hello, I have a bit of a technical question. I am working with a publisher who has requested I insert some functions into the code (such as PUBLISHER_GAMESTART which they can call to begin the game or PUBLISHER_SUBMITSCORE to collect highscore data). These are requested so they can hook the game into their API.

    My original assumption was that I could simply use the Function plugin to accomplish this. For instance I have a loader layout which moves to the title screen only when the function "PUBLISHER_GAMESTART" is called using the "On function" event.

    Unfortunately, I have no way of knowing if the javascript developers who work with this company will be able to access the functions via a normal text editor. Looking at the code for myself, it looks rather mangled and does not resemble functions I have seen in the past (though this may be a result of my inexperience). The code is not minified.

    I think my question, then, is: If I tell the publisher that the function they can call is "PUBLISHER_GAMESTART"--will they be able to accomplish this through their own methods?

  • the function plugin dont create a function like

    function myFunction(param1){


    It's something used by the construct 2 engine for the event system and I dont think you can access it externaly.

    Instead, I would create a plugin for your publisher using the construct SDK

  • The Function object works exclusively with events, it does not work with Javascript. For your case you need to use the Javascript SDK.

  • Miste is right. the Function Plugin is not actually javascript function code.

    For what you want. I suggest either trying one of the javascript plugins or writing your own plugin that provides the publisher hooks.

    Unfortunatly there is no easy way for this to work. Unless of course the js plugin can do what you want.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is actually not hard to do, you just need to use the plugin that jayderyu mentioned. Then it's as easy as adding the "Execute" action from that plugin to any part of your game. For instance, after a button is pressed, add the CallJS execute action and enter one of the names of the javascript functions the publisher needs, like "PUBLISHER_SUBMITSCORE()".

    You don't need to do anything else.

    As for the function to start the game it's a bit more technical but still easy. You can't add that function inside C2, you need to add it after you export the game by editing the index.html with a text editor. You only need to make 1 edit:

    Find the line: // Start the Construct 2 project running on window load.

    There you'll find the following code:


    jQuery(document).ready(function ()
              {              ?
                  ?// Create new runtime using the c2canvas

    You need to replace all of that with this new code:

         {              ?
         function PUBLISHER_GAMESTART()
       jQuery(document).ready(function () 
                  ?// Create new runtime using the c2canvas

    On the new code, replace PUBLISHER_GAMESTART with any name you need for the function to start the game. Everything should be ready after that.

  • That makes sense. I'll see how well I'm able to put it together for them and let you know the results. They also want some empty functions so they can add in their content. I'm assuming I should just include some hollow functions in the external js file the plugin requires and then call the functions within C2.

    Thank you so much for the help! I'm not sure how I could have done this without some input from people who know more about the undercarriage of the program.

    Edit: Ok, so I have run into a bit of a hiccup. It's fairly straight-forward calling functions which exist outside of Construct, but what if the publisher wants a function which they can call to affect the game? In this case, they want to be able to pause the game by calling PUBLISHER_TOGGLEPAUSE().

    I have looked around for further help on the CallJS plugin, but very little exists. I can't figure out what the events included in the plugin do, or if they would be of any help. I thought maybe I could have PUBLISHER_TOGGLEPAUSE() flip a variable on and off in the js file which CallJS could then read, but I'm not sure CallJS does any reading at all.

  • You should just use the Javascript SDK. CallJS amounts to a very hacky version of doing what the SDK does well, and the SDK also allows for other javascript events to fire triggers in the event system, which should do what you want.

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