Search code examples
androidgoogle-play-servicesmultiplayergoogle-play-games

Is there any way to pass information when inviting to a Turn-based match in Google Play Multiplayer?


This seems like it would be a very common scenario, so I am somewhat puzzled at not being able to find support for this in the Google Play services.

Essentially, I have a turn-based multiplayer game. It has multiple scenarios that the player can chose to play - either single-player or multiplayer. The inviting player of course gets to chose what game he wants to play.

However, there seems to be no way to communicate to the invited player, what he is being asked to play. Where there are multiple scenarios, the invited player may not be equally willing to play all scenarios, but at present the invited is forced to accept the invitation before being able to see what they've just said yes to.

Or have I overlooked something? Alternately, any way to handle this in a smart way?


Solution

  • Invitations provide the ability to set a Variant that can advertise a discrete set of values, see the Invitation Java doc.

    I have an example in one of my apps where I create a Turn based game, and set the variant, like so:

    TurnBasedMatchConfig tbmc = TurnBasedMatchConfig.builder()
            .addInvitedPlayers(invitees)
            .setAutoMatchCriteria(autoMatchCriteria)
            .setVariant(variant)
            .build();
    

    This should propagate the variant to the Invitation that the invited player(s) see. I don't think the standard Google Play Service Invite handler shows the variant, but if you have an in-game invite handler, you could check what the variant is and display it in some way.

    I know that this variant works for me for "automatch" both in realtime and in turn based games, although I also seem to remember that in some cases I did not get a valid value for the variant- I think a likely bug in the Game Play services. I tried to find what I thought was a stackoverflow question I would have upvoted and answered, but I only found a previous answer to a similar question.