Today I'm proud to announce, that my GameJolt API plugin for Construct 2 has been finally updated to support most of site's functions.
This means that you can now display highscore tables and trophies in your game, access Data Store, and more.
You can get the updated extension and example from the GameJolt page, or read this post for few more details.
Firstly, to mention why there was such a delay between initial release and this update.
Making easy to use Construct 2 plugins can be a bit of a trouble sometimes.
While the fact that you define UI and runtime parts of plugin separately is generally good, it also means that the process takes more time on average, since you need to define everything twice and also ensure that you did not make any mistakes and everything works as intended on both sides.
Another trouble is interface. For a plugin like GameJolt API you send data to site, and wait for response. Response is normally handled either synchronously (meaning that game freezes while it's waiting for a response) or via a callback function (that is called as soon as response arrives).
In Construct 2, however, you (by default) only have events, which are kind of like callbacks, but are global, and don't support arguments.
So... what I ended up doing after a while, is having global variables that allow you to determine, what the event applies to, dispatching the event, and having good faith in you not trying to access the variables outside of their respective events.
You can now fetch contents of any given highscore table.
Mechanism is as following:
- You request highscores to be fetched via Scores - Get Scores (or Get Local Scores to get highscore table entries just for the current player).
- Extension forms and sends the request, and waits for response to arrive.
- Extension dispatches a Score - Scores received event. At this time you have ScoreTable to know which table the scores are coming from, and ScoreCount determining number of returned scores (in case you need to prepare for handling them).
- Extension dispatches series of Score - Score entry events, one per every score entry. These contain the multitude of variables starting with Score and correspond to individual score entry information. ScorePlace contains index/place of score entry in table, starting with 1 and ending at ScoreCount (inclusive). ScoreTable remains set and still can be used to distinguish score tables
- Extension dispatches a Score - Scores complete event to mark the fact of all score entries being processed.
Score submitted event has also been updated and now sets some of Score* variables, but only ones that have been provided in action itself (because GameJolt does not respond with information like place achieved).
You can now also fetch trophy status(es) for your game.
The mechanism is very alike to that of scores, except for lack of "received"/"complete" events.
An important thing to note here is that you can provide trophy IDs as a comma-separated list, e.g. "5980,5981,5982".
"Trophy achieved" callback only gets to know TrophyID, and TrophyAchieved, which is set to "just now" if trophy achievement was confirmed, and an empty string if it failed.
Finally, there are now functions and events to work with Data Store. Data Store is awesome.
Possibilities are almost endless, and are primarily only limited by your imagination & creativity.
Each Data Store action dispatches an according event of it's own, containing StoreKey (and StoreLocal) to allow telling requests apart, and StoreValue containing new or retrieved value.
It is also worth mentioning, that "update" events also return (updated) values, meaning that you don't have to spend an extra request to retrieve the new value.
You can get the updated extension and example from game's page, or via these links of fair convenience:
As usual, you can ask any questions, if needed.
And if you like what I'm doing, consider supporting me on Patreon :)