The following code is a simple example of how to send an achievement unlock call. There is also a button to display the achievement list. Note, the example is using JQuery and the code is wrapped in window.idAsyncInit to ensure ID is created by the id.net SDK before calling it.

Example

<a href="#" id="achlist">Display Achievements</a>
<a href="#" id="achsave">Unlock Achievement</a>

<script>
window.idAsyncInit = function() {
  // use an idnet event to wait until after init
  ID.Event.subscribe('id.init', function(){
    $('#achlist').click(function(){
      ID.GameAPI.Achievements.list();
    });

    $('#achsave').click(function(){
      var achievement = {
        achievement: "Super Monkey",
        achievementkey: "1f8c317c550bd6c1a0e2"
      };
      ID.GameAPI.Achievements.save(achievement, function(data){
        console.log(data);
      });
    });
  });
};
</script>

Achievements and leaderboards must first be setup on the application page.


Achievement Reference

Achievement List

ID.GameAPI.Achievements.list(options)

Will dislpay all achievements. If a player is logged in, it will display show shich achievements have been unlocked.

options - An object with additional options. In most cases this can be left out of the call.

Achievement Save

ID.GameAPI.Achievements.save(achievement, callback)

Unlock an achievement for a player.

achievement - an object containing the following properties

  • achievement: The title of the achievement. This must exactly match.
  • achievementkey: The unlock key generated from the achievements application page. This must also exactly match.
  • overwrite: (optional)(default: false) Allow players to unlock the same achievement more than once.
  • allowduplicates: (optional)(default: false) Allow players to unlock the same achievement and display them seperatly.

callback

  • A callback function with 1 argument for return data.

Achievement List Custom

 ID.GameAPI.Achievements.listCustom(options, callback)

Will return the achievement list data so that a custom dialog can be used. If an achievement in the list contain a player varible, this means that it was unlocked. See the page about achievement response data for details about unlocked achievements.

options An object with additional options. In most cases, an empty object is best. ex. {}

callback

  • A callback function with 1 argument for return data.

Leaderboards Reference

Leaderboards Tables

ID.GameAPI.Leaderboards.tables(callback)

Return an app’s tables to a callback. Useful only when table names are unknown.

callback

  • A callback function with 1 argument for return data.

Leaderboards List

ID.GameAPI.Leaderboards.list(options)

Display the high scores menu.

options - an object containing the following properties

  • table: The exact table name from the app’s high scores page at id.net. This is also the menu title.
  • mode: (optional) A string that equals alltime, last30days, last7days, today, or newest.
  • highest: (optional)(default: true) Set to false if a lower score is better.
  • allowduplicates: (optional)(default: false) Set to true if player’s can have more than one score displayed.

Leaderboards List Custom

ID.GameAPI.Leaderboards.listCustom(options, callback)

Returns score data for custom high score menus.

options - an object containing the following properties

  • table: The exact table name from the app’s high scores page at id.net. This is also the menu title.
  • mode: A string that equals alltime, last30days, last7days, today, or newest.
  • perPage: (optinal)(default: 20) Number of results to show per page. Max 100.
  • page: (optinal)(default: 1) A number representing the paged results.
  • highest: (optional)(default: true) Set to false if a lower score is better.
  • allowduplicates: (optional)(default: false) Set to true if player’s can have more than one score displayed.
  • playerid: (optional) A string representing the player’s id or pid. Used for getting the player’s score(s)

callback

  • A callback function with 1 argument for return data.

Leaderboards Save

ID.GameAPI.Leaderboards.save(score, callback)

Saves a player score.

score - an object containing the following properties

  • table: The exact table name from the app’s high scores page at id.net.
  • points: A number representing the player’s score
  • allowduplicates: (optional)(default: false) Set to true if player’s can submit more than one score.
  • highest: (optional)(default: true) Set to false if a lower score is better.
  • playername: (optional)(default: id.net nickname) Set when player’s in-game username is not the id.net nickname

callback

  • A callback function with 1 argument for return data.