[BUG] gameNetwork iOS multiplayer sample app -- GC Game Over screen shows opposite results or both win

I’ve been investigating the sample app (https://github.com/coronalabs/gameNetwork-iOS-turnbased-multiplayer) as I build head-to-head match game for the iOS version of my game, and I see the Game Center Game Over screen displays either the opposite results or both of them as winners

I mean, say, I have two sandbox players, Tester1 and Tester2.

Tester1 starts an auto-match game.  Finishes a turn.

Tester2 starts an auto-match game, which essentially lets Tester2 join the match game Tester1 has started.

Eventually, Tester1 finishes the game (while still waiting for Tester2 to finish).  So Tester1 taps on BACK button.

Then Tester2 proceed to take turns and finish the game.

On Tester2’s game screen it says:

GAME OVER

YOU:  1250

P2:  950

Tester1 eventually taps on JOIN MATCH button, which brings up the GC’s Game Over screen, and all I see is:

3 minutes ago

ME

Won (which is the opposite of what actually happened.)

However, if Tester1 and Tester2 never go back out of the game and completes the game, and both of them see the GAME OVER screen with the results inside the game itself, the GAME OVER screen shows winner/loser correctly.  The problem is, when both Tester1 and Tester2 tap on BACK button, then tap on JOIN MATCH button, they see both of them as the winner of the last game played.

I guess I’ll just have to file a bug report for this?

Naomi

Edit:  BTW, my GC Game Over screen shows Tester1 has lost a couple of games (2 out of 8 games played), so I know it doesn’t always show that the user won.  I just don’t have time to work out how I can get it to display “Lost” instead of “Won” right now.

Edit2:  Bug filed Case 25594

I also noticed the same thing along with a few other quirks. I think the sample is effective for showing how the basics of GC multiplayer works but it certainly could be improved further to cover additional ground and offer a more complete view.

And, I’d be sooo happy if I could rely on API doc 100% even if the sample app has quirks and issues…  It just troubles me that we’d need to do some trials and errors to sort things out (and especially if I end up writing code that contradicts with what API doc says I must do… which makes me feel like things will break down the road even if my experimental implementation works now.)

Naomi

Added challenge is the fact that you can only test these things on a device where you normally don’t have the benefit of print statements to help you understand whats going on. I found extreme benefit in jstrahan’s _applog library which is currently in beta. With it I can see the print statements on device so understanding whats going on under the hood gets a little easier. Most recommended. 

Thank you, @ksan, for mentioning jstrahan’s _applog library.  Perhaps I should look into it.

Naomi

Hmmmm… actually, maybe I’m not seeing things correctly, and the sample app might be working just fine.  I just don’t know.

I just got my multiplayer game work all the way through, and on GC Game Over screen, it shows who won on both devices.  Meaning, instead of saying ME Lost, it only shows ME Won or Other Tester Won.  (I wonder how I got “Lost” to show up with sample project though.)

Naomi

I think the sample app is showing the game over screen itself. I don’t think that black screen is the GC screen. So it must be a simple programming error. I didn’t fully review it yet either but I’m glad to hear your own app is working well. This means there is hope for me yet! :slight_smile:

I think I found the bug and fixed it. Now it works well for me. If anyone is interested in a working game over for the GC Sample Apps replace the following function in game-scene.lua with the revised version below. 

local function decodeData(data) player1ID = data.player1ID player2ID = data.player2ID p1total = data.player1 p2total = data.player2 if imPlayer1() then p1score.text = string.format( "YOU: %6.0f", p1total ) p2score.text = string.format( " P2: %6.0f", p2total ) gameOverText2.text = string.format( "YOU: %6.0f", p1total ) gameOverText3.text = string.format( " P2: %6.0f", p2total ) else p1score.text = string.format( " P1: %6.0f", p1total ) p2score.text = string.format( "YOU: %6.0f", p2total ) gameOverText2.text = string.format( " P1: %6.0f", p1total ) gameOverText3.text = string.format( "YOU: %6.0f", p2total ) end end

The above correction fixes the game over screen you see on the device. However, there is still something wrong. The results you see on the GC screen always shows same side won over the other side regardless of who actually won. I tracked it to the following if/then statement

if player1ID and player1ID == storyboard.myPlayerId and p1total > SCORE_LIMIT then

in function gameOver(). 

Something is wrong there.

I also noticed the same thing along with a few other quirks. I think the sample is effective for showing how the basics of GC multiplayer works but it certainly could be improved further to cover additional ground and offer a more complete view.

And, I’d be sooo happy if I could rely on API doc 100% even if the sample app has quirks and issues…  It just troubles me that we’d need to do some trials and errors to sort things out (and especially if I end up writing code that contradicts with what API doc says I must do… which makes me feel like things will break down the road even if my experimental implementation works now.)

Naomi

Added challenge is the fact that you can only test these things on a device where you normally don’t have the benefit of print statements to help you understand whats going on. I found extreme benefit in jstrahan’s _applog library which is currently in beta. With it I can see the print statements on device so understanding whats going on under the hood gets a little easier. Most recommended. 

Thank you, @ksan, for mentioning jstrahan’s _applog library.  Perhaps I should look into it.

Naomi

Hmmmm… actually, maybe I’m not seeing things correctly, and the sample app might be working just fine.  I just don’t know.

I just got my multiplayer game work all the way through, and on GC Game Over screen, it shows who won on both devices.  Meaning, instead of saying ME Lost, it only shows ME Won or Other Tester Won.  (I wonder how I got “Lost” to show up with sample project though.)

Naomi

I think the sample app is showing the game over screen itself. I don’t think that black screen is the GC screen. So it must be a simple programming error. I didn’t fully review it yet either but I’m glad to hear your own app is working well. This means there is hope for me yet! :slight_smile:

I think I found the bug and fixed it. Now it works well for me. If anyone is interested in a working game over for the GC Sample Apps replace the following function in game-scene.lua with the revised version below. 

local function decodeData(data) player1ID = data.player1ID player2ID = data.player2ID p1total = data.player1 p2total = data.player2 if imPlayer1() then p1score.text = string.format( "YOU: %6.0f", p1total ) p2score.text = string.format( " P2: %6.0f", p2total ) gameOverText2.text = string.format( "YOU: %6.0f", p1total ) gameOverText3.text = string.format( " P2: %6.0f", p2total ) else p1score.text = string.format( " P1: %6.0f", p1total ) p2score.text = string.format( "YOU: %6.0f", p2total ) gameOverText2.text = string.format( " P1: %6.0f", p1total ) gameOverText3.text = string.format( "YOU: %6.0f", p2total ) end end

The above correction fixes the game over screen you see on the device. However, there is still something wrong. The results you see on the GC screen always shows same side won over the other side regardless of who actually won. I tracked it to the following if/then statement

if player1ID and player1ID == storyboard.myPlayerId and p1total > SCORE_LIMIT then

in function gameOver(). 

Something is wrong there.

I’d like to see an overall better example of using the gamenetwork object. I’ve been completely confused about how it works for about a day now. The documentation is too sparse. I want to know exactly when certain events are meant to fire, and what exactly that means in the context of a game.

One problem I currently have is when I send the request for endmatch, it doesn’t end the match for the other player. The other player is just sitting there waiting… So I tried doing endturn, then endmatch, but that’s not quite working correctly either, and it’s difficult to debug having to keep installing it on two devices every time.

By the way, ksan, if you’re on a mac:

  • Go to the Organizer window

  • Go to your connected Device.

  • Click Console

It will show your print statements there.

I’d like to see an overall better example of using the gamenetwork object. I’ve been completely confused about how it works for about a day now. The documentation is too sparse. I want to know exactly when certain events are meant to fire, and what exactly that means in the context of a game.

One problem I currently have is when I send the request for endmatch, it doesn’t end the match for the other player. The other player is just sitting there waiting… So I tried doing endturn, then endmatch, but that’s not quite working correctly either, and it’s difficult to debug having to keep installing it on two devices every time.

By the way, ksan, if you’re on a mac:

  • Go to the Organizer window

  • Go to your connected Device.

  • Click Console

It will show your print statements there.