Some trouble figuring out Game API

I’m having trouble figuring out how to use the Game API’s achievement and leaderboard calls. I’m able to use the list function just fine, but anything that has to do with saving doesn’t seem to do anything. I’m pretty much copying the examples from this page:
http://dev.id.net/docs/javascript/game-api/

For example, this call doesn’t print anything to console:

ID.GameAPI.Achievements.save(achievement, function(data){
            console.log(data);
          });

And when I call this:

ID.GameAPI.Achievements.list();

The achievements lists are shown, but the achievement was never unlocked.

Maybe I’m missing something obvious. Any help is appreciated, thanks!

Hi, have you checked in app console on id.net hitcounter for particular achievement?
(go to id.net on menu choose applications and choose on this one ‘achievements’ button) You have a counter that is showing you if achievement was unlocked - otherwise there are zeros everywhere. If you still have zero it means it wasnt unlocked propertly (its counting global events for each achievement).

are you sure you have exact names in achievement list including achieve id and there are no doubles?

It sounds like you are missing the init function. All game API calls should be wrapped in the init call. Most lists can work without the init call. However, for player specific ones, the init is required. I will update the docs to explain this.

See this line in the Game API docs

ID.GameAPI.init('APP ID HERE', null, function(data, response){

Hmm, i do have that init function and the call is wrapped inside it. I’m wondering if I’m not handling the login and redirect correctly. Maybe I’m not putting things in the right order? Anyhow, here is the full section of code for when the app starts up:

window.idAsyncInit = function() {
// When SDK is ready and when id.init event is triggered (all initialization processes are done i.e. ID.init called)
// We register an event with jQuery
// on click on the connect link it will open the ID.net authentication modal window
ID.Event.subscribe('id.init', function(){
  $('#idnet-connect').on('click', function(){
    ID.register();
  });

  ID.GameAPI.init('MY APP ID THAT I FOUND ON DASHBOARD', null, function(data, response){
    console.log(data);
    $('#achlist').click(function(){
      console.log("achlist");
      ID.GameAPI.Achievements.list();
    });

$('#achsave').click(function(){
  console.log("achsave");
  console.log(data);
console.log(response);
  var achievement = {
    achievement: "TEST",
    achievementkey: "UNLOCK KEY FROM DASHBOARD"
  };
  ID.GameAPI.Achievements.save(achievement, function(data){
    console.log(data);
  });
});
  });
});

// init the ID JS SDK
ID.init({
    appId         : 'MY APP ID THAT I FOUND ON DASHBOARD',                              // App ID from the app dashboard
    status        : true,                                       // Check Id.net Login status
    responseType  : 'code',                                     // 'token' by default
    redirectUri   : 'https://localhost:4443'    // default redirect_uri
  });
};

and @martin, yes i did check the app console’s hitcounter and it is still zeros everywhere.

Everything looks good from what I can see. You mentioned the redirect. I would try using the token based login unless you need a server to do id.net calls on behalf of a user. Also, with the token based login, a callback can be used to get the return data. This way avoids redirects.

ID.init({
    appId : 'APPID'
});

ID.register(function(response){
    console.log(response)
});

wow okay that solved my problem! thank you thank you thank you thank you thank you :blush:

I will update the docs. :grinning: I realize that it could be more clear as there are a lot of options.

A post was split to a new topic: Adding Y8 games to another site

Y8 Games