2
\$\begingroup\$

I have been following this tutorial for Google Play Game Services. I am a little unclear as to if the room matching algorithm should be looped or not. Can I just initialize this process once and let it time out? Or by iterating through it is it somehow rechecking it? If anyone had the approximate timeout that would be great as well.

The problem stems from the fact that even when both phones are signing into the Game Services (at virtually the same time, my friend and I logged in), the room is not registering multiple people. One time my friend's phone even entered the game map, showing that he somehow was able to progress from the room initialization process.

Relevant screen update methods which I am starting this matchmaking process:

@Override
public void update(float deltaTime) 
{
    game.options.updateTiles();

    if(!isInitiated) 
    {
        startQuickGame();
    }
}

private void startQuickGame() 
{
    // auto-match criteria to invite one random automatch opponent.  
    // You can also specify more opponents (up to 3).
    if(game.mGoogleClient.isConnected() && !isInitiated) 
    {
        Bundle am = RoomConfig.createAutoMatchCriteria(1, 3, 0);

        // build the room config:
        RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(Network.getInstance());
        roomConfigBuilder.setMessageReceivedListener(Network.getInstance());
        roomConfigBuilder.setRoomStatusUpdateListener(Network.getInstance());
        roomConfigBuilder.setAutoMatchCriteria(am);
        RoomConfig roomConfig = roomConfigBuilder.build();

        // create room:
        Games.RealTimeMultiplayer.create(game.mGoogleClient, roomConfig);

        // go to game screen
        this.mRoom = Network.getInstance().getRoom();
        if(this.mRoom != null && this.mRoom.getParticipants().size() >= 2) 
        {
        game.setScreen(new MultiGameScreen(game, this.mRoom));
        isInitiated = true;
        }
    }
    else 
    {
        game.mGoogleClient.connect();
    }
}
\$\endgroup\$
7
  • \$\begingroup\$ I was hoping maybe someone on the Android development team had an answer to this. The code would dictate that it would create a new room perhaps every loop. Should I try a standard timeout sequence? \$\endgroup\$ – A13X Jun 6 '14 at 17:56
  • 1
    \$\begingroup\$ I'm just guessing here going by the documentation, but it seems like you should only create the room once, set isInitiated to true, then wait for participants using the connecting players code: developers.google.com/games/services/android/… \$\endgroup\$ – Ethan Worley Jun 10 '14 at 1:36
  • \$\begingroup\$ I will try that, this may be the answer and I obliviously overlooked some simple participant checks. \$\endgroup\$ – A13X Jun 10 '14 at 1:41
  • \$\begingroup\$ Any luck with the participant stuff? \$\endgroup\$ – Ethan Worley Jun 11 '14 at 1:53
  • \$\begingroup\$ It appears there is still a NPE when creating the Game Screen. I am not getting a ton of feedback from the Stack Trace. Looking through the connection code I implemented, it DOES pass code that knows there are two or more players currently in the lobby. Since the NPE is at a line of creating the game screen and gc the current screen, the mRoom object may be deleted or something. \$\endgroup\$ – A13X Jun 13 '14 at 2:08
1
\$\begingroup\$

I'm just guessing here going by the documentation, but it seems like you should only create the room once, set isInitiated to true, then wait for participants using the connecting players code found here: https://developers.google.com/games/services/android/realtimeMultiplayer#connecting_players

By overriding the RoomStatusUpdateListener.onPeersConnected method, you can keep a count of the number of players and only move to the game screen when you've reached the minimum required players.

The startQuickGame method currently appears to be creating a Room each update. I believe you want to create the room once, then keep a reference to this room and wait for players.

From this question on stackoverflow, it appears the Room will not time out by default.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks. I hope others can learn from this too, so there is better multiplayer implementation. My game has gotten past that error. Thanks again! \$\endgroup\$ – A13X Jun 25 '14 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.