You're looking at our questions archive. This question was last updated over 1 year ago.
If you're looking for help, head over to the Parse Developers Google Group or check out the parse.com tag on Stack Overflow.Help Google Group Stack Overflow
8 votes 1 answer 5.48k views over 1 year ago
I have created a 2 person asyncronous game. I want players to get paired up with random other players, however this is difficult to do without writing any server side code.
Ideally I would want to have a person save a game request to Parse, then another could pull a game request from Parse and claim it. However there is nothing really stopping 2 players from pulling the same game request and both trying to claim it. Is there anyway to pull a game request and somehow lock it so no one else can pull it. Or is there another way to get this sort of functionality?
David's solution is clever and works (incrementKey is atomic). If a GameRequest object is created with a "challengers" : 0 value, then each challenger could call
incrementKey:@"challengers". If, after
save, the value of challengers is 1, then they are the first committed challenger. I particularly like this solution since it works for N player games as well. Similarly, you can use
addUnique: (also atomic) to add a User ID to a list of challengers.
You might also consider a solution which uses push notifications to propose matchups. You can use this to break ties in the host (whichever challenger reaches the host first is paired) and to get the user's attention if he has left the application.