11 years ago

Gamejolt game achievements for Gdevelop


Hi all, so I am going to present you how to add Gamejolt game achievements into your game.

We are going to use a javascript api for that, it was created by Maus.

Thanks a lot for your api Maus :)

First of all, we have to download Maus api.

That’s the link :

http://gamejolt.com/games/other/game-jolt-api-js-library/22948/

After you have to edit that file : GameJoltAPI/source/gj-js-api to write on the top of the file

your game id and your private key(those information are on Dashboard/your_game_name/Achievements).

you have to insert your game id into GJAPI.iGameID and your private key into GJAPI.sGameKey on the top of the file.

After that you have to add the file to your Gdevelop project, for that you have to activate c++/javascript functionalities ( it’s on the game property). Then you can add the javascript source file.

So now we can use all functions of that file. The only thing to do is to use those function on our scenes.

We are going to look at adding Highscores, it’s more or less the same thing for other things(add trophies, data store …).

We have to add in our scene a javascript event to add javascript code.

Next step is to create a javascript variable and to get the value of the the global variable or the variable of the scene.

This is the first line of the code:

varJavascript = runtimeScene.getVariables().get(“varScore”).getAsNumber();

runtimeScene : we choose the scene where the javascript event is.

runtimeScene.getVariables() : we ask for variables on that scene.

runtimeScene.getVariables().get(“varScore”) : we choose the variable varScore.

runtimeScene.getVariables().get(“varScore”).getAsNumber() : we get the value of the variable varScore.

For further details on javascript events, read the documentation : http://wiki.compilgames.net/doku.php/gdevelop/tutorials/usingjsevents

Our javascript variable got now the score. We just have to use functions now for add the score by passing into parameters

the javascript variable varJavascript.

The code below is fonctionnel but it’s not perfect, I don’t understand all thing of imbricated functions however I think that it is possible

to don’t have imbricated functions(the code was obtained by modifying the html file GameJoltAPI/source/test).

73531 represent the id of the High Scores table, you have to change it by yours which are displayed there(Dashboard/your_game_name/Achievements/High Scores).

I recommend you to read the documentation of the api for more information about functions : http://www.maus-games.at/files/gamejolt/js/

this is the rest of the code:

var sSaveUserName = GJAPI.sUserName;

var sSaveUserToken = GJAPI.sUserToken;

GJAPI.UserLogout();

GJAPI.UserLoginManual(sSaveUserName, sSaveUserToken,

function(pResponse)

{

// ****

// TROPHY

var nTrophyFetchCallback =

function(pResponse)

{

};

GJAPI.TrophyAchieve(73531,

function(pResponse)

{

});

GJAPI.TrophyFetch (GJAPI.TROPHY_ALL, nTrophyFetchCallback);

GJAPI.TrophyFetchSingle(73531, nTrophyFetchCallback);

// ****

// SCORE

var iNewScore = varJavascript;

GJAPI.ScoreAdd(0, iNewScore, iNewScore + “Points”, null,

function(pResponse)

{

GJAPI.ScoreAddGuest(0, iNewScore, iNewScore + ” Points”, “Nobody”, null,

function(pResponse)

{

GJAPI.ScoreFetch(0, GJAPI.SCORE_ALL, 10,

function(pResponse)

{

for(var i = 0; i < pResponse.scores.length; ++i)

{

var pScore = pResponse.scores[i];

}

});

});

});

});

Thanks for your attention :)

By MiniDream.



3 comments

Loading...

Next up

Shoobies leave a sticky trail of mucus in their wake, which can impede movement for any creature that steps in it.

"Thanks guys for endless hours of fun." 👍

(My first fan art. Read the article, please.)

#sonic #mario #photoshop

Here's a peaceful little forest scene for this #screenshotsaturday, from the beginning of the game.

Enemies can also suddenly spawn through Realm Rifts. These Rift Spawns are going to be stronger than the ones wandering around. TBD on the enemies... #screenshotsaturday #godstear #madewithunity

Another house i made long time ago.

Microsoft Windows XP Unprofessional (windows logo prototype)

Shuiro Haname. #Commission

Commission for @ShuHaname

Today I tackled drawing different variations of facial expressions for one of the main characters in Eden. What do you think of it? :) Eden: https://gamejolt.com/games/Eden/592698

Levels' maps.

Who's is this little cutey👸 here? Thanks🙏 for a gorgeous fanart @WheNa! Feel free to share your arts, screenshots, or videos with #playzelter or #zelter hashtags! #pixelart #animating #unity3d #animated #indiegames #unrealengine #animate #conceptart