Corona weekly update: Turn-based multiplayer support

Corona weekly update: Turn-based multiplayer support

Game-Center-iconReady to invite your friends to play your latest game? You’re in luck!

Starting in Daily Build #1172, you can develop iOS games that take full advantage of turn-based multiplayer features in Game Center.

We’ve built all these features into the ‘gameNetwork’ library so whether you have existing code or new code, it’ll be a cinch to use.

There’s a full sample available: https://github.com/coronalabs/gameNetwork-iOS-turnbased-multiplayer.

Here’s a quick tour:

To invite players, you create a match with specific player id’s:

To auto-match players, you also create a match but you specify the number of players you want to match:

You can also mix and match, inviting some some players and then also auto match players to the same match:

When the request listener is fired, the events contain a property ‘event.type’ that takes on the following values:

  • invitationReceived
  • matchEnded
  • playerTurn

Perhaps the coolest thing is that notifications that tell you it’s your turn are automatic, so you don’t need to do anything!

Happy coding!

[Update] We also plan to add support for Game Center features added to iOS 6 such as invite messages, player attributes, and player groups.

walter
22 Comments
  • Chris
    Posted at 09:23h, 31 July

    Sounds good. Even though I don’t really know how to get the player Ids of the friends (is there maybe a way to get all the gamecenter friends and their corresponding ids to invite them?). Hope we’ll see someone using that feature 🙂

  • dchan
    Posted at 09:56h, 31 July

    @Chris
    You can get the ids of your friends with this:

    local function requestCallback(event)
    print(event.data[1].playerID)
    end

    gameNetwork.request( “loadFriends”, { listener=requestCallback } )

    Note that this only gets the ids of your friends and not their aliases. To get their aliases you have to do something like this:

    gameNetwork.request( “loadPlayers”,
    {
    playerIDs =
    {
    “G:123456789”,
    “G:1234567890”,
    “G:0123456789”
    },
    listener=requestCallback
    })

    There is an example of this in our sample code located here:
    https://github.com/coronalabs/gameNetwork-iOS-turnbased-multiplayer/blob/master/menu-scene.lua#L70

    Hope this helps and happy coding!

  • Chris
    Posted at 10:19h, 31 July

    Oh thanks for the quick help 😀

  • ed69
    Posted at 12:29h, 31 July

    @Walter – thanks a lot for this new functionality, but unfortunately it doesn’t looks complete! Could you please let us know if other important parameters for the matchmaking request are available like:
    – inviteMessage,
    – playerAttributes,
    – playerGroup,

    as they are originally available in GC:
    http://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKMatchRequest_Ref/Reference/Reference.html

    • dchan
      Posted at 18:45h, 31 July

      @ed69
      We did not implement inviteMessage because that is an iOS 6+ feature. Since we support iOS 5 we didn’t want to have some functionality that wasn’t available for all the iOS platforms we support.

      As for the other 2, those are not vital to implementing turn based multiplayer. This will be something we will implement in the future on a second pass.

      • ed69
        Posted at 11:37h, 01 August

        @dchan – sorry, but this explanation is very very weird – how could you decide to block feature development just because it is iOS6+ ?
        iOS7 will be released soon and beta release build is already integrated in the Corona SDK!
        As Kerem also kindly pointed you – Apple already reported that more than 94% of the iOS customers are using iOS6!

        Regarding features which are “vital” or either not for the turn based multiplayer – how could you take this responsibility on you to decide which functionality should be available in my final product and which not?
        I’m paid pro Corona SDK customer and I expect to have full functionality for the turn based multiplayer support as it is stated in second sentence of this blogpost (and especially if other developers also explicitly asking about this)!
        For example, I need to have “playerGroup” option available, to be able to split players which would like to play in different game modes with each other – and this is essential for every multiplayer app today!
        How should I resolve this – any proposals? And could you please provide any reasonable argumentation why it was not implemented?

        On the other hand – If you are not able and not going to provide full support for turn based multiplayer on iOS – please ask Walter at least to fix the title of this blog post to something like “Turn-based multiplayer support only partially available” – this would be more fair and will not confuse other developers.

  • Kerem
    Posted at 23:37h, 31 July

    @dchan, the question is what % of devices are still running IOS 5 and whether this is a large enough % to hold back such a critical function (ie inviteMessage)… According to the OpenSignal report (http://opensignal.com/reports/fragmentation-2013/) we are talking 95% to 5%… Perhaps this decision needs to be re-considered.

  • Andreas
    Posted at 00:25h, 01 August

    This is great, turn based multiplayer is the genre I love most.

    +1 for the iOS 6+ “inviteMessage”, this is absolutely needed.

    Best,
    Andreas

  • Overtorment
    Posted at 13:56h, 01 August

    I think that might be also used to matchmake realtime multiplayer games.
    Corona handles matchmaking and user ids, and all game interaction can be made in publish/subscribe channel. Check out this library for self-hosted solution https://github.com/Overtorment/NoobHub

  • ed69
    Posted at 03:27h, 02 August

    NoobHub is a nice service which I have tried already earlier – it is definitely possible to buildup completely working multiplayer with it, but it will require to host my own server (or server farm even) to install it and to configure it, to take care about keep it up and running, to setup monitoring and load tracking and etc. – all stuff you need to have if you would like to go on with your own servers plus of course it will be not for free – it will be needed to pay for hosting and spend a lot of working time on this!

    But the point is – all this, not really needed to be done at all, as soon as full featured multiplayer services are already available from Apple side (and for very long time already) and which I (in theory) able to use absolutely for free as subscribed Apple iOS developer – BUT they are just blocked in Corona SDK implementation for unknown reason!
    This is what I’m trying to clarify here – why it is implemented only partially that in any more or less serious game it will be just not usable or looks unprofessional?

    @Walter – could you please clarify why this implementation was done in a such bad way? Could it be, that these 3 additional parameter are skipped away from integration in Corona SDK just to have another reason to proposed developers to buy more expensive product “Enterprise Edition”?

    • David Rangel
      Posted at 07:47h, 02 August

      ed69 – thanks for the comments.

      First of all, no, we did not take out 3 parameters just to make you upgrade to Corona Enterprise. That has never been our intention with any features we do/do not implement.
      There are 2 things that happened here:

      1) The team made a call on what to prioritize given some internal deadlines and those 3 parameters were left out of the *first pass*
      2) There was a slight miscommunication with Walter, hence the “full support” headline

      We do understand your feedback. Notice that both Danny and I mention this is a *first pass*. I personally will see what we can do to include these other items ASAP.

      David

    • Walter
      Posted at 09:29h, 02 August

      Okay, I’ve added an update at the bottom of the post to clarify.

      @ed69, I want to prioritize this appropriately, so can you help us understand how these iOS 6-specific GC features play a critical role in your game?

      For example, the wildly successful Letterpress (v1.4) game works uses Game Center extensively. However, it works on iOS 5, so it does not utilize any iOS 6-specific GC features.

  • ed69
    Posted at 15:17h, 02 August

    @David & @Walter – thank you a lot for clear responses!
    From my side I’m happy to help, especially if this will speedup and improve situation.
    First of all I’d like to explain why missing parameters (at least for me) making the current turn based multiplayer practically not usable.

    1. The most critical and important for me is the missing parameter “playerGroup” – it is not mandatory required in GameKit from Apple side, but it is de facto must have, as soon as there is more than one play mode in the game (and it is like that in the most of the games). For example, if we have 2 maps in the game to play it is needed to split all users on 2 groups and provide this information to the Game Center that matchmaker function will know that players in group 1 should play on the map 1 with players from group 1 and not with players from group 2 which should play on the map 2. Same use case we have also with the card/board games – for example there is many variants of the checkers game (like board size 8×8 or 10×10 and other game rules modifications) which required also correspondently to split users on the specific groups: users who select 8×8 boards cannot play with the users who select 10×10 boards, but only on the same sizes of course. Hope this is clear, here is the link to the GameKit docu from Apple: http://developer.apple.com/library/ios/documentation/GameKit/Reference/GKMatchRequest_Ref/Reference/Reference.html#//apple_ref/occ/instp/GKMatchRequest/playerGroup

    2. “playerAttributes” – also missing in current implementation, for me it is not critical right now, but for convenience it will make sense to implemented it together with the “playerGroup” property. Documentation for it is available here: http://developer.apple.com/library/ios/documentation/GameKit/Reference/GKMatchRequest_Ref/Reference/Reference.html#//apple_ref/occ/instp/GKMatchRequest/playerAttributes

    Please note – this two properties “playerGroup” and “playerAttributes” are not newly invented in iOS60 – they are actually available since iOS4.1.

    3. “inviteMessage” – this is a relative new iOS6.0 property which allows to make your custom invite text message to be displayed for the player to join the match. Of course it is possible to initiate multiplayer match without it, but this is what make your (our) apps looking more professional when they have this fine customization, but I can leave without this (and as Letterpress probably also).

    4. “maxPlayersAllowedForMatchOfType” – strictly speaking as from iOS6+ this function is must have and should be used before to set maxPlayers parameter in the matchmaking request (as required by Apple).

    Please let me know if there other questions to clarify.
    Would be also great to get clear feedback from you when these missing parameters will be integrated (or may be one by one, like playerGroup and then others, if you would like to do it like that).

    • David Rangel
      Posted at 15:20h, 02 August

      Great, thank you for the feedback!
      We’ll discuss on Monday in our engineering meeting and I’ll have an update.

  • Mario Roberti
    Posted at 10:28h, 03 August

    Ah excellent! This looks to be a great place to turn after the Corona Cloud package was discontinued. Can’t wait to start digging in after my current project is finished!

    -Mario

  • ed69
    Posted at 10:24h, 06 August

    @David & @Walter – could you please provide an update regrading missing properties?
    Basically it should not be much work to add them to the existing implementation – as I understood it is required only to add them to the gameNetwork.request and then pass from lua to the GameKit as it is done already for parameters playerIDs, minPlayers and maxPlayers and that’s it, isn’t it?

    • ed69
      Posted at 10:35h, 07 August

      … downloading already a new build 2013.1180 with all mentioned properties included!
      Thank you a lot for the support!

      • David
        Posted at 10:47h, 12 August

        Yup – it is now in daily builds!

  • Kerem
    Posted at 10:59h, 07 August

    Build 1181 logs

    iOS: Add support for playerGroup, playerAttribute, inviteMessage, and maxPlayersAllowedMatch to iOS turn based multiplayer.

    Great job!!! Thank you very much for being so responsive to feedback. Have a great day.

  • Muchacho
    Posted at 13:20h, 12 August

    I am a programmer in training, and so far I have used Kwik to create apps, adding custom code here and there. I have read the Corona Cloud documentation, as well as the GameCenter documentation, and this document. But I still don’t understand a few things. Does one need a Corona Cloud account to implement the features described in this article? or does this happen in the GameCenter (Apple) backend? Does this require a yearly subscription?

    I would appreciate some pointers on understanding how all this works together.

    Thanks in advance.

  • GregH
    Posted at 20:34h, 19 February

    Anyone able to give a really high level overview of where this fits in with using something like http://parse.com/ ? For example (I’ll take an educated guess) would it be that with the apple specific approach it focused only on turn-based support but is free. WIth http://parse.com/ it’s only free up to a certain level of usage (then paid) but would give you cross platform (e.g. IOS/Android) for players spread across both, plus give you customized server side function, plus support for customized push notifications. Am I close? 🙂