I'm trying to make a real-time peer-to-peer multiplayer game with GameKit/Game Center. I'm trying to store a dictionary of player IDs and scores ([String:Int]
) to keep track of and share player scores during a game. Essentially, I want to be able to increment the score of a player locally, then send the updated scores dictionary to all the other players.
However, the GKLocalPlayer.local.gamePlayerID
seems to be in a completely different format than any other connected GKPlayer
, so when I try to access the GKMatch.players
with the gamePlayerID
, it isn't found (and yes, I'm aware that GKMatch.players
doesn't contain the local player).
The GKPlayer
has an 18-digit long integer, whereas the GKLocalPlayer
has A:_ and then a long hexadecimal number (I think it's 37 digits in decimal).
Can someone explain this difference or point to some resources that explain how I can implement this functionality correctly?
Here's a simplified example of what I'm doing:
var scores: [String:Int] // dictionary of [gamePlayerID:Score]
scores[myMatch.players.first.gamePlayerID] = 3
scores[GKLocalPlayer.local.gamePlayerID] = 5
sendScores(scores) // sends data to all players using myMatch.sendData()
/*
When the receiving players decode and try to access scores[gamePlayerIDOfSendingPlayer],
it isn't found because it's different from that player's gamePlayerID
in the receiving player's GKMatch.players array
*/