Multiple APIs implemented in one project?

Get help using Construct 2

Post » Wed Jan 29, 2014 2:21 pm

Hello everyone,

I was wondering if there are some good practices on how to implement different website APIs in the same project. Let's say I want to have leaderboards and achievements on Gamejolt, clay.io and Newgrounds, how should I go about this? Use the same conditions and trigger everything at the same time, regardless of the website it's hosted or is there any way to detect the website in which the game is hosted?

I am no expert in this matter and I'd like your opinion.

Thanks :)
B
33
S
9
G
3
Posts: 493
Reputation: 4,042

Post » Wed Jan 29, 2014 2:25 pm

A quick and dirty approach could be as simple as defining a global var with the name of the target site.

Meaning you would still have to export 3 times, but only change one variable for each export.

On the events where you use the needed sdk, simply add a subevent checking for the global variable.

Add a check for this variable where applicable to determine which to use.



There is also a method to check the URL of a website through the browser object, through this you could determine what the global variable should be and have the process automated.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Wed Jan 29, 2014 4:32 pm

Maybe using different event sheets for each API and then triggering different functions depending on the URL would be an option? I just don't know how to detect the host...

I mean, I would like to export my project only once and upload it to multiple sites at the same time, since I fix bugs and add features quite often.
B
33
S
9
G
3
Posts: 493
Reputation: 4,042

Post » Wed Jan 29, 2014 6:43 pm

The export takes only a minute so exporting different builds for each should not be that hard, especially if all you need to change for each one is a variable as mentioned above. I export for Windows 8, Google, Nook, Kindle, Tizen and more and have no problem exporting a separate copy for each one. It's really not hard and takes no extra effort than clicking your mouse. You still only have to fix the bug once, then just export again for each one.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583

Post » Wed Jan 29, 2014 7:51 pm

There is a System condition for "Is on platform":

[QUOTE]
Is on platform
Test if currently running on a given platform, such as Android or as a Windows 8 app. Note it's possible multiple options can be true simultaneously. For example, if running in a browser on Android, both Is on platform Android and Is on platform HTML5 website will be true.[/QUOTE]

Source: https://www.scirra.com/manual/124/system-conditions
B
20
S
4
G
1
Posts: 185
Reputation: 2,563

Post » Wed Jan 29, 2014 8:30 pm

You can use the browser's object domain or url expression to access the current domain or URL.

Then decide which API you want to talk to.

JohnnySheffield2014-01-29 20:32:16
Be nice until it's time to not be nice
B
36
S
10
G
9
Posts: 293
Reputation: 6,712


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 52 guests