Question about GameKit in Cabrera's "Beginning iPhone Games Development" book

Apprentice
Posts: 11
Joined: 2009.01
Post: #1
Hi! I'm learning from Cabrera's book how to make networked games via Bluetooth using the Game Kit framework.

On page 564, the author mentions something that when certain statement inside the receiveData:fromPeer:inSession:context method gets called, we can be sure that the value inside the "myDiceRoll" variable already contains the results from our own roll attempt. I tried to make sense of that sentence by looking through GameKit's documentation but I don't understand how can we be 100% sure that "myDiceRoll" is valid. Isn't it possible that somehow we receive the data from the other device so fast that we don't to get to generate our own data?

I'm sure that many of you have read the book, so I'd be very thankful if you can enlighten me Grin

Cheers,

--Nacho
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #2
Figure 14-8 on page 558 shows why. In the algorithm, Player 1 rolls the dice and sends the message to Player 2 before checking for messages from Player 2.

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
Apprentice
Posts: 11
Joined: 2009.01
Post: #3
Thanks for your reply!

Yes, I had looked at that diagram before posting but I wanted to know how that algorithm was reflected in the code. If you look at the code listing, the call to the diceRolled method is performed at the bottom of the peerPickerController:picker:didConnectPeer:toSession:. My question is: how can we be sure that the receiveData:fromPeer:inSession:context: method would never be called before we get to execute the [self diceRolled] statement? I think that the answer is related to the fact that this program is running in a single thread, but I'm not completely sure about it...

Cheers,

--Nacho
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #4
You may want to ask on the book's forum.

http://iphonedevbook.com/forum

The author of the networking chapters has the username byteclub on the forum.

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Is it possible to implement http connection for iPhone Development? joyjit_b 2 5,553 Aug 8, 2008 09:13 AM
Last Post: Taxxodium
  Beginning development Hawksun 28 10,846 Jun 16, 2002 04:44 PM
Last Post: Carlos Camacho