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

Today I was setting up the location of the first boss. His name is "Father" and he is the first of the Patagonians. His task is to guard the road to the House.🛡🗡 Bookmark pre-launch page🔖🔖🔖

https://www.kickstarter.com/projects/rdvindiegame/the-patagonian…

I-Buki

Mio-Da!

Ibuki Mioda!

The Darkside Detective: A Fumble in the Dark is out TODAY! 🖱️Advanced pointing, clicking action 🖨️Very funny words! Loads of them! 👻6 sarcastic, spectral cases to solve

Horror WIP A track that will be featured in a future horror game soundtrack! Stay tuned!

Likes appreciated ✌️

#gamedev #composer #horrorgame #indiegame #IndieGameDev #soundtrack

Rockin the Guitar, an Axe like Guitar I made for my Uni project

Regular exercise is key for healthy wings.

Try it out!

https://gamejolt.com/games/AeonNightmares/605184

"Day to Day" (also check spud out here he's a great guy and writer: https://soundcloud.com/spudward)

If you’ve played the Vault demo and enjoyed it, please consider ‘liking’ the game page here on Gamejolt and/or leave a comment!

Also please consider tossing Vault on your Wishlist, I really appreciate your support!

https://store.steampowered.com/app/1251800

Explosive domino effect

Our menu, gathered a huge feedback and positive comments among foreign audience, what you say? Game Steam: https://store.steampowered.com/app/1543090/LiBER/