Game API
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 Y8 Account SDK before calling it.
Example
Achievements and leaderboards must first be setup on the application page.
See the Achievements Management and Scores Managment pages for more details.
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.
- embedded: (optional)(default: false) Hide the backdrop, should be used with closeMenu()
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 Y8 Account. 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.
- useMilli: (optional)(default: false) Render scores in milliseconds.
- embedded: (optional)(default: false) Hide the backdrop, should be used with closeMenu()
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 Y8 Account. 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.
- 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 Y8 Account.
- 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: Y8 Account nickname) Set when player’s in-game username is not the Y8 Account nickname
callback
- A callback function with 1 argument for return data.