Instance Property

playerGroup

A number identifying a subset of players allowed to join the match.

Declaration

var playerGroup: Int { get set }

Discussion

If your game sets the playerGroup property, only players whose requests share the same playerGroup value are automatched by Game Center. Setting the playerGroup property to 0 allows the player to be matched into any waiting match. Set the playerGroup property to a nonzero number to match the player only with players whose match request shares the same player group number. The value of a player group is arbitrary. For example, you could define different playerGroup values to implement any of the following filters:

  • A game could restrict players based on skill level.

  • A game that provides multiple game modes could use it to filter players into the specific game they want to play.

  • A game that provides bonus content through in-app purchase could match players who own the same content with each other.

Listing 1 shows how you might configure a match request that uses a player group. In this example, the player group value is calculated by choosing both the map the player wants to play on and the rules set under which the player wants to play. A constant for each is chosen and the two are bitwise ORed together to create a unique number for the player group. Game Center only searches for other players with the same map and group combination.

Listing 1

Creating a player group based on the map and rule set

GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 4;
request.playerGroup = MyMap_Forest | MyRulesCaptureTheFlag;

See Also

Creating Subsets of Players

var playerAttributes: UInt32

A mask that specifies the role that the local player would like to play in the game.