API integration

0 favourites
  • 11 posts
From the Asset Store
This is a simple login feature to access Metamask in construct 3. Requires a Chrome Browser and Metamask Extension.
  • Hi Everyone,

    I am trying to integrate an API in my HTML5 game. The javascript for that is in index.html. I am able to call that function from Contruct 2 by using CallJS plug in. But how will I able to call a function of Contruct 2 from javascript ?

    Or, to be specific,, I want to make an event happen in Contruct2 after the API get ended.

    Thanx in advance.

  • Do you have a personal or business license, for if not it is not allowed to make money from Construct 2.

    I'm asking because you dont have the medal on your avatar.

  • One simple thing you could do, if you don't want to write a plugin, would be to check every tick a variable in the page, or the result of a function in the page. You can call the ExecJS function inside a "System:Compare two values" for example.

    More detail example :

    I have in my page a function "A" that collects informations to be send to C2. Each time I have to send informations to C2, I call this function, it stores datas.

    I have another function "B" that displays this information in a string encoded how it fits me. When this function is called, the stack of informations to be send to C2 will be emptied.

    Now in C2, in an EveryTick event, I would start by setting a local variable to the result of the call to the function "B" via an ExecJS. Then, I would read this variable. Explode, JSON decode->put it in an array, whatever fits, and do a for each to treat every action.

  • I am trying the software before buying it. So, I am trying all features we will need.

  • Guizmus: Can you please provide a quick capx for this. I tried your solution, but I am missing something and I don't know which. PLEASE

  • Can't provide a capx, it all depends on your API for the actual integration. Mostly, it would go something like this :

    capx organization

  • Guizmus: I basically want that from javascript, I could do something which will make my connection back to Construct 2. So after completion of an javascript function, I should return back to construct 2 and continue further.

    Putting all in a nutshell, Is there a way to change value of a variable in construct 2 from javascript function ?? That is all I needed to solve my question

  • The the solution I described should work then.

    You should be able to update a variable in C2 from the webpage by looking into the runtime object, in a javascript debugger too though. C2 is running on the page, so you could change the variable there. But as this wouldn't trigger a function in C2, having an interface between the page and C2 is more versatile.

  • Guizmus: So does that mean the value returned by function (in your case my_functionB) is getting loaded in the array ?

    In that case, cant I directly set value of a variable to Browser.ExecJS("my_functionB")

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes of course. I used array to carry multiple datas at once.

  • Thanx for a satisfactory reply. I will do this and tell you the result soon.

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