IOS multiplayer -- how can I retrieve a list of ongoing matches from GC

I would like to retrieve a list of open / ongoing matches from GC and put it in a tableView so that my app user can select a game in progress and go back to it without having to delve into Game Center. I would like to abstract the GC interface as much as possible and keep the game player in my game interface where possible. Thanks much for your help.

Hi,

You can do something like:

gamenetwork.request(“loadMatches”) which will return all the matches that involve the player in an array.  Each match has a status field you look at to see the status of it.

There are 4 possible statuses for a match

  • unknown - The match is in an unexpected state
  • open - The match is currently being played
  • ended - The match has been completed
  • matching - Game Center is still searching for other players to join the match

http://docs.coronalabs.com/daily/api/type/GameNetwork/match.html

Thank you so much for the hint. I appreciate it. Is there any way to get info on whose turn it is to play next? It would be great if this info is also returned for matches with status = open. 

Yes the match object also has a currentParticipant property.  It also has an array of all the participants.

http://docs.coronalabs.com/daily/api/type/GameNetwork/match.html

Super. Time to go reading then! :slight_smile: I will try to add this to the sample and see how far I get. Your help is most appreciated. 

Ok. I am getting somewhere… 

I added a 3rd button to the sample

 local showMatchText = display.newText( screenGroup, "SHOW MATCH", display.contentWidth \* 0.5, display.contentHeight - 130, "Futura-CondensedExtraBold", 30 ) showMatchText:setReferencePoint( display.CenterReferencePoint ) showMatchText.x = display.contentWidth \* 0.5 showMatchText:setTextColor( 255, 255, 255 ) showMatchText:addEventListener( "touch", buttonPressed ) showMatchText.tag = 3 

And then the following to the function buttonPressed()

 elseif target.tag == 3 then local function matchesListener(matchesLoadedEvent) storyboard.matchesArray = matchesLoadedEvent.data for i = 1, #storyboard.matchesArray, 1 do print(storyboard.matchesArray[i]) end end storyboard.gn.request("loadMatches", {listener = matchesListener}) 

using @jstrahan’s excellent blackBox utility I was able to quickly verify that I am getting the matchesArray nicely populated. I now need to figure out the structure of the table that is returned (yes I need to read the docs… :slight_smile: and put it all in a tableView. Important thing is that data is coming back from GC. More to follow.

A little table snooping like so

for i = 1, #storyboard.matchesArray, 1 do local matchData = {} matchData = storyboard.matchesArray[i] print(storyboard.matchesArray[i]) for key,value in pairs(matchData) do print(key,value) end end

gets the following… One record only shown here for clarity

participants table: 0x21460ee0
status ended
currentParticipant table: 0x21461770
data {“tableData”:{“params”:[5,2,150,22],“moves”:[[“yellow”,“red”,“yellow”,“blue”,“red”,“green”,“green”,“blue”],[“blue”,“yellow”,“yellow”,“blue”,“blue”,“red”,“blue”,“green”],[“yellow”,“green”,“green”,“yellow”,“red”,“yellow”,“blue”,“green”],[“red”,“green”,“yellow”,“green”,“green”,“green”,“blue”,“blue”],[“green”,“blue”,“green”,“yellow”,“blue”,“yellow”,“blue”,“red”],[“blue”,“blue”,“green”,“blue”,“yellow”,“red”,“red”,“blue”],[“green”,“red”,“red”,“blue”,“yellow”,“green”,“red”,“yellow”],[“red”,“blue”,“yellow”,“green”,“blue”,“yellow”,“red”,“yellow”]]},“player2”:1100,“player1ID”:“G:1208612449”,“player2ID”:“G:228725820”,“player1”:0}
matchID f99f5171-2ee6-47c0-83e3-d9bd240ba56c

This is good stuff!!! Thanks!!!

@dchan, one last question on this topic if I may… 

When I look at my match data in GC I see a date in each match record. I don’t see this date returned along with match data in Corona SDK. Is there a way to get it included in the data returned by gamenetwork.request(“loadMatches”) ? 

Thanks so much for your help.

Currently that is not returned in Corona but it will be added soon.

That sounds great!!! I can start with what I have now and add the date later on. Your continued efforts are most appreciated. 

Hi,

You can do something like:

gamenetwork.request(“loadMatches”) which will return all the matches that involve the player in an array.  Each match has a status field you look at to see the status of it.

There are 4 possible statuses for a match

  • unknown - The match is in an unexpected state
  • open - The match is currently being played
  • ended - The match has been completed
  • matching - Game Center is still searching for other players to join the match

http://docs.coronalabs.com/daily/api/type/GameNetwork/match.html

Thank you so much for the hint. I appreciate it. Is there any way to get info on whose turn it is to play next? It would be great if this info is also returned for matches with status = open. 

Yes the match object also has a currentParticipant property.  It also has an array of all the participants.

http://docs.coronalabs.com/daily/api/type/GameNetwork/match.html

Super. Time to go reading then! :slight_smile: I will try to add this to the sample and see how far I get. Your help is most appreciated. 

Ok. I am getting somewhere… 

I added a 3rd button to the sample

 local showMatchText = display.newText( screenGroup, "SHOW MATCH", display.contentWidth \* 0.5, display.contentHeight - 130, "Futura-CondensedExtraBold", 30 ) showMatchText:setReferencePoint( display.CenterReferencePoint ) showMatchText.x = display.contentWidth \* 0.5 showMatchText:setTextColor( 255, 255, 255 ) showMatchText:addEventListener( "touch", buttonPressed ) showMatchText.tag = 3 

And then the following to the function buttonPressed()

 elseif target.tag == 3 then local function matchesListener(matchesLoadedEvent) storyboard.matchesArray = matchesLoadedEvent.data for i = 1, #storyboard.matchesArray, 1 do print(storyboard.matchesArray[i]) end end storyboard.gn.request("loadMatches", {listener = matchesListener}) 

using @jstrahan’s excellent blackBox utility I was able to quickly verify that I am getting the matchesArray nicely populated. I now need to figure out the structure of the table that is returned (yes I need to read the docs… :slight_smile: and put it all in a tableView. Important thing is that data is coming back from GC. More to follow.

A little table snooping like so

for i = 1, #storyboard.matchesArray, 1 do local matchData = {} matchData = storyboard.matchesArray[i] print(storyboard.matchesArray[i]) for key,value in pairs(matchData) do print(key,value) end end

gets the following… One record only shown here for clarity

participants table: 0x21460ee0
status ended
currentParticipant table: 0x21461770
data {“tableData”:{“params”:[5,2,150,22],“moves”:[[“yellow”,“red”,“yellow”,“blue”,“red”,“green”,“green”,“blue”],[“blue”,“yellow”,“yellow”,“blue”,“blue”,“red”,“blue”,“green”],[“yellow”,“green”,“green”,“yellow”,“red”,“yellow”,“blue”,“green”],[“red”,“green”,“yellow”,“green”,“green”,“green”,“blue”,“blue”],[“green”,“blue”,“green”,“yellow”,“blue”,“yellow”,“blue”,“red”],[“blue”,“blue”,“green”,“blue”,“yellow”,“red”,“red”,“blue”],[“green”,“red”,“red”,“blue”,“yellow”,“green”,“red”,“yellow”],[“red”,“blue”,“yellow”,“green”,“blue”,“yellow”,“red”,“yellow”]]},“player2”:1100,“player1ID”:“G:1208612449”,“player2ID”:“G:228725820”,“player1”:0}
matchID f99f5171-2ee6-47c0-83e3-d9bd240ba56c

This is good stuff!!! Thanks!!!

@dchan, one last question on this topic if I may… 

When I look at my match data in GC I see a date in each match record. I don’t see this date returned along with match data in Corona SDK. Is there a way to get it included in the data returned by gamenetwork.request(“loadMatches”) ? 

Thanks so much for your help.

Currently that is not returned in Corona but it will be added soon.

That sounds great!!! I can start with what I have now and add the date later on. Your continued efforts are most appreciated.