API integration

Get help using Construct 2

Post » Fri Jan 31, 2014 1:01 pm

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.Raganork2014-01-31 13:20:31
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Fri Jan 31, 2014 1:07 pm

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 31, 2014 1:09 pm

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.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Fri Jan 31, 2014 1:15 pm

I am trying the software before buying it. So, I am trying all features we will need.
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Fri Jan 31, 2014 1:29 pm

@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. PLEASERaganork2014-01-31 13:29:38
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Fri Jan 31, 2014 1:52 pm

Can't provide a capx, it all depends on your API for the actual integration. Mostly, it would go something like this :
capx organization
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Fri Jan 31, 2014 2:02 pm

@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 questionRaganork2014-01-31 14:03:13
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Fri Jan 31, 2014 2:15 pm

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.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Fri Jan 31, 2014 2:20 pm

@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")
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Fri Jan 31, 2014 2:28 pm

Yes of course. I used array to carry multiple datas at once.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000, max2612 and 8 guests