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

This Satuday we invite to watch another #speedpainting of our artist Daniel Faiad.

How great is this scene of #Pecaminosa?

#ScreenShotSaturday | #IndieDev | #DigitalArt

"Thanks guys for endless hours of fun." 👍

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

#sonic #mario #photoshop

Heya there! I really wanted to show you all a little gameplay preview of the first boss fight i'm currently working on i hope you like it ^^

What do you think guys in my robot?Just a beginner in 3d modeling..

My instagram https://www.instagram.com/rojhonbb/

Just a Pico sprite

Back in my art school days I used to ride the 710 COPSA line from Parque Del Plata to Montevideo almost everyday. This is the Marcopolo Viaggio G4 Mercedes Benz model from the late 80s, one of the older bus models that was running on the line.

Finished work on the emotions of a new character for the tank universe

Update 2.627

New challenges & new effects!

I worked so hard to get all four of them to the end safely, but then...

Let me introduce you to the new Mech line: Gendai Spec. Those are Mech that specializes in surprise attacks, covered operations, and stealth. They are equipped with melee weapons but one of Gendai's frames supports sniper rifles.