Initialize

The Leaderboards Javascript SDK allows you to easily submit scores and show a full Miniclip leaderboard for all of the submitted scores from your game. The leaderboard contains various features such as a global leaderboards, friends leaderboards, event leaderbaords and time filters.

To use the Leaderboard Javascript SDK only need to do two things:

  • Include the file https://static.miniclipcdn.com/js/mc.js as specified here</li>
  • Once this script is included, you then need to initialise the API with the module you want to use. In this case it is the Leaderboard module. For example:
<script type="text/javascript">
	MC.init({
		modules: ['Leaderboard'],
        leaderboard: {}
	});
</script>

Show Leaderboard

Shows the leaderboard for a specified level.

Leaderboard Screenshot

Request

Parameter Type Description
level integer The level of the game for which you want to display the leaderboard
callback function his is called upon opening and closing of the leaderboard. The callback passes back 1 and 2 back respectively for these conditions

MC.Leaderboards.show() response callback returns 2 possible values:

  • 1 - leaderboard has been opened
  • 2 - eaderboard has been closed

Example

MC.Leaderboard.show(0, function(code){});
Sample successful response
// leaderboard openned
1
// leaderboard closed
2

Show All Leaderboards

The level list needs to be set during the SDK initialization. Either by defining the min and max number of levels, or by describing the complete level list.

<script type="text/javascript">;
    MC.init({
        modules: ['Leaderboard'],
        leaderboard: {
            min: 0,
            max: 25,
            level_info: [
                { level: 0, name: "World 1"},
                { level: 1, name: "World 2"},
                { level: 2, name: "World 3"},
                { level: 3, name: "World 4"}
            ]
        }
    });
</script>
Parameter Type Description
callback function his is called upon opening and closing of the leaderboard. The callback passes back 1 and 2 back respectively for these conditions

MC.Leaderboards.showAll() response callback returns 2 possible values:

  • 1 - leaderboard has been opened
  • 2 - eaderboard has been closed

Example

Define the level list on the sdk initialization:

// Miniclip sdk initialization with named levels
MC.init({
	modules: ['Leaderboard'],
	leaderboard: {
		level_info: [
			{ level: 0, name: "World 1"},
			{ level: 1, name: "World 2"},
			{ level: 2, name: "World 3"},
			{ level: 3, name: "World 4"}
		]
	}
});

Open the leaderboard list dialog:

MC.Leaderboard.showAll(function(code){});
Sample successful response
// leaderboard openned
1
// leaderboard closed
2

Save Score

Save a score for a particular level to miniclip.

Request

Parameter Type Description
score_data Score Request This contains data necessary to save the score
callback function<Score Response> Method called on completion

Example

To save the score 100000 of level 0:

MC.Leaderboard.saveScore(
	{ level: 0, score: 10000},
	function(response){
		if (response.success)
			console.log("Save score was successfull");
		else
			console.log("Save score failed");
	});

Response

// structure of response
{
	"success":true,
	"is_highscore":false,
	"message":"",
	"awards":{
		"0":{
			"id":"540",
			"name":"Gravity Guy Silver"
		},
		...
	}
}

Get User Highscore

Gets raw JSON data containing the logged in users current highscore in the specified level. It will use the data from the monthly global leaderboard as this leaderboard will always contain the highest score.

Request

Parameter Type Description
level integer Level you want to get the highscore from
callback function  

Response

Field Type Description
success boolean  
message string  
data Highscore Object  

Example

To get the user highscore from level 2:

MC.Leaderboard.getUserHighscore(2, function(response){});

Response

// structure of response
{
	"success": true,
	"message": "",
	"data": {
		"user_id": 20130297,
		"score": 10000,
		"rank": 1,
		"nickname": "Mark",
		"country": "PT",
		"country_name": "Portugal"
	},
}

Get Raw Leaderboard

Gets raw JSON data for the specified level

Request

Parameter Type Description
level integer Level you want to get the leaderboard from
callback function  

Response

Field Type Description
success boolean  
message string  
data Array<Rank Object>  

Example

To get the user highscore from level 2:

MC.Leaderboard.getRawLeaderboard(2, function(response){});

Response

// structure of response
{
	"success": true,
	"message": "",
	"data":[
		{
			"avatar":"//images.miniclipcdn.com/avatars/20130297-40.png",
			"country":"PT",
			"country_name":"Portugal",
			"is_logged_in_user":true,
			"nickname":"Mark",
			"rank":"1",
			"score":"140,050",
			"user_id": 20130297
		}
	]
}

Resources

Score Request Object
Field Type Description
level integer Which level this score belongs to
score float the score value
Score Response Object
Field Type Description
success boolean  
is_highscore boolean If the submitted highscore is the highest score of the level
message string  
awards object  
Highscore Object
Field Type Description
country string Country code of the user
country_name string Country name of the user
nickname string User nickname
rank float The highscore rank
score float The score
user_id integer  
Leaderboard Rank Object
Field Type Description
avatar string User avatar url
country string Country code
country_name string Country name
nickname string User nickname
rank float Position in the leaderboard
score string Formated score
user_id integer