Once you understand the basics of the SMP system, the matchmaking class can help skip some of the trouble of filling game rooms efficiently. The system comes with a auto join room function that will rank a player’s skill and find the best game room for them.

Ranking Options

Decide on the best ranking for your game. Note only one can be used at a time.

  • Fill rooms without any player ranking. (default)
  • Rank players based on a score in an advanced leaderbaord table.
  • Rank players based on the amount and difficultly of achievements unlocked.

Setup Requirements

Once the multiplayer code is initalized, we must then initialize the matchmaking code. This happens in the smp callback. In the below example, a high score table named ‘Farthest Distance’ is used for ranking.

var started = false;
function smp(msg){
	if(msg.action == 'start' && !started){
		started = true;
		sdk.matchmaking.startMatchmaking();
		sdk.matchmaking.maxPlayers = 2;
		sdk.matchmaking.playerRankTable = 'Farthest Distance';
	}
}

The following is a list of properties available in the matchmaking class:

minPlayers:int = 2;
maxPlayers:int = 10;
joinAnytime:Boolean = true;
playerRankTable:String = '';
highest:Boolean = true;
useAchievements:Boolean = false;

Remember to set the min and max players per a room if they are different from the defaults. Also, choose a ranking option using one of the above properties.

Auto Game Joining

Once the multiplayer class is initialized and matchmaking is ready, make the autoJoinGame function available to the player.

sdk.matchmaking.autoJoinGame();

Example

A working game was made to test the matchmaking code. Download the example and run it with Flash CS6+ or see the main.as and swf.