Communicate between C2 and html

  • Hi =)

    I'm looking for the proper way to communicate between c2 and my own JS functions in the html file.

    I can't find a good c2 JS reference, for instance the cr_setSuspended function is even not documented !

    So how do I :

    • modify c2 global variables from the html page ?
    • call a function defined in the c2 event sheet from the html ? Pass in variables ?
    • call a js function from c2 and handle the return value ? Calling Brownser Go to url "javascript:..." cannot get the value returned.

    Thank you so much for your help =)

  • You can use the CallJS plugin to call javascript functions, but I'm not sure how to do the other things.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thanks ! That will help a lot ! I'm wondering why those basic features are not implemented in C2.

    So this plugin can call js from c2.

    I will also need the inversed way, calling c2 functions from JS.

    If we can grab object with getElementById("myC2TextBox") there should be a way to call c2 functions as well !

    thank you for your help ;)z

  • Does this topic helps ?

  • yes it helped to understand that textboxes can be accessed by id in the html. But you can't access global variables or functions like that.

  • What's the use case? I can understand calling functions from a library, but why are you putting your own js in the html? It sounds like whatever functionality you're trying to achieve would be better as a plugin.

  • Is setting a session web storage variable a option for you? Just check it's content every now and then..

  • I'm actually building a lottery like game with an opt-in form that tells if you can play or not. I'm using custom html/css/jquery to setup the form as I can't do this properly in C2. So when the form is submitted, I do some ajax to register the user before he can play. Then I need to call a game function to launch the right layout etc.

    I managed to trick this, changing a textbox value inside C2 from my custom JS, and on C2 listening for the textbox value to change :

    <img src="http://api.imajao.com/photo/EDJDI.png" border="0" />

    but this is not a proper way to do this simple thing^^

  • anthonyk You should really use plugins for this sort of functionality. Have a look at the clay.io plugin for some examples of overlayed form functionality integrated into a plugin.

  • thank you for the advice ! This plugin sounds really great !

    I'll take a look ;)

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