Integrating APIs

Discussion and feedback on Construct 2

Post » Thu Sep 01, 2011 9:48 pm

As you might know, there are (besides the big players like steam) some open platforms for casual/indie games. One of them is Kongregate

They offer an relatively easy to use API, supporting ActionScript 2/3 and Javascript.
Have a look at the Javascript API. How could it be integrated to C2?
Following the link, you can see that they also offer a html shell to make things easier. You need to embed the game in order to use the shell, of course. Does this work with C2?

In addition, there's the server-side JSON API, used for payment, high scores, badge feeds, etc. Again, how would that be integrated?

I know, that the API works for non-flash games, as I have tested several Unity games there. But I'm an absolute beginner when it comes to Javascript/html5.

Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Sep 04, 2011 12:42 am

Anyone?

I'm not looking for a complete solution to this problem, just a description of the way it would have to be done, maybe with some keywords that I can then google for. Or a statement that it isn't possible.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Sep 04, 2011 3:21 am

I'm not a kongregate user, so I don't really know how it works on their site.

From what I can see, I'd say you would have to modify the index.html file of an exported project and add the line:
[code]<script src='http://www.kongregate.com/javascripts/kongregate_api.js'></script>[/code]
With the others "scripts" lines.
That would allow the API to be available to your application.

The tricky part would be using
[code]// Load the API
var kongregate;
kongregateAPI.loadAPI(onComplete);

// Callback function
function onComplete(){
// Set the global kongregate API object
kongregate = kongregateAPI.getAPI();
}[/code]

That initiates the kongregate's API in conjunction with the already present code that launches the C2 runtime in index.html.

[code]// Start the Construct 2 project running on window load.
        jQuery(document).ready(function ()
        {
            // Create new runtime using the c2canvas
              cr.createRuntime("c2canvas");
        });
[/code]

Try to put the kongregate's code prior to C2's.
This might work, or you might end up with an issue because jQuery isn't used for kongregate. I don't really know at this point.


A plugin would then be the interface calling the JS kogregate's API functions according to C2 events. (this is pretty much the same as using jQuery functions in a plugin, I think the subject is evoked in C2's sdk).


On the other hand, the server-side API is really simple. Just throw ajax calls at the urls indicated. You don't even need another plugin for that and can handle it through events pretty easily.

JS is pretty straight forward to get used to (especially if you coded in other languages).
Just check out MDN JS guide for starters.

Hope it helps.Kyatric2011-09-04 03:25:05
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805

Post » Sun Sep 04, 2011 3:44 am

Thank you very much, Kya, that helps a lot. I always try to solve issues, but in cases like that, I need a starting point. You just gave me one :)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Sep 04, 2011 10:01 pm

Most javascript APIs should be straightforward to throw in to a plugin. Things like this we would do ourselves, but we have so much other work to do it will probably be put off for a long time until we get round to it. If third party plugin developers can pick up little jobs like this, it's really helpful to us and frees us up for other editor work and the like. Still, if nobody does as I said we'll eventually try to get round to it.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Mon Sep 05, 2011 12:33 am

I can probably pick this up, but I can only work on stuff during weekdays. I still have to finish my bouncing ball behavior, fix that bug with the turret object (as well as implement the stuff that is missing and optimizing it), do the docs for all of them (those will probably have to wait a bit) and crank out a couple tutorials.
Funny how I'm overworked with scirra stuff, and I don't even work there :PFimbul2011-09-05 00:36:09
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Mon Sep 05, 2011 1:02 am

That would be awesome!
In the meantime, while you are optimizing your current plugins, I will start teaching myself javascript and test my capabilities. Kyatrics online version of the C2 SDK documentation is very useful, and from what I see it seems to be a straightforward adaptation of the C++ SDK for CC, so it shouldn't be too difficult.
Then again, learning is much harder as you get older... :D
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Sep 05, 2011 3:06 am

[QUOTE=tulamide]Kyatrics online version of the C2 SDK documentation is very useful, and from what I see it seems to be a straightforward adaptation of the C++ SDK for CC, so it shouldn't be too difficult.
Then again, learning is much harder as you get older... :D[/QUOTE]

Beware though, the HTML version of the sdk is not up to date.
Be sure to dld Ashley's SDK package.

But yes, learning gets hard, but JS appeared quite simple, and when oriented at plugin developement, it is almost "follow the guide" :)
Kyatric2011-09-05 03:06:48
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests