dvd.Void
dvd.Void

Reputation: 369

GameCenter: Player Groups

I'm working on a game for iOS. I am up to a part where I need to start filtering matches so people get paired up properly. I was reading about player attributes and player groups and due to the nature of my game PlayerGroups are the way to go.
As I am reading in the Apple documentation, they provide this example:

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

Now, I am totally sure there are some parts missing, but my main questions are:
What is | (the vertical line). Is player group an array? or what is it? Reading their documentation it says its an Unsigned 32 bit integer, how is that converting into 2 different values separated by a vertical line?.
Also, Apple says:

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.

This is very vague, I'm not sure if I make the constant or if they make it or who makes it? and I'm not sure if there's a typO at the end and they meant map and rules instead of map and group (given the example). Also, if they are OR'ed then the match will be EITHER in forest map OR capture the flat, but not both, and I assume you want both if you set those parameters.

Anyways, Does anyone know more about this and can provide me a better example or explain a little bit better how to use PlayerGroups? Thank you!

Upvotes: 0

Views: 121

Answers (1)

T Tse
T Tse

Reputation: 846

What apple is saying is that the group can be a Bit field. Only the players with the same value for the group will be matched together.

As for why the OR operator is used there, it is just used commonly for bit fields. Technically you can use + there.

Let's say the dev in the example decided to make the least significant byte used for the map, and the second least for the game mode, then the group would be:

   MyMap_Forest          00000000 00000000 00000000 00001001
OR MyRulesCaptureTheFlag 00000000 00000000 00000011 00000000
------------------------------------------------------------
                         00000000 00000000 00000011 00001001

You can see that both the information in which map to use and which mode to play are both contained in the result.

Upvotes: 1

Related Questions