Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Multiplayer games

edited November 2013 in Questions Posts: 5

Is it possible (or easy?) to create a game that can be made mutiplayer? so for example say i have a chess game and i wanted to make it two player but with anyone who uses the app. can codea allow for development of these types of games? player opens the app and sees list of players who are free to play anywhere who are using the app. they click and join the game and play.

Hopefully this logic is possible?


  • dave1707dave1707 Mod
    edited November 2013 Posts: 7,612


  • Posts: 8

    @dave1707 i think what he means is a game where it sets you up with another player playing the game on another device @Wirewolf86 if this is the case then you could use HTTP but it would get pretty messy and you would need to write some server software too.

  • IgnatzIgnatz Mod
    Posts: 5,396

    At the moment it's not easy to play with someone else over the internet, especially a real time game. A turn based game is possible, but as Ducky says, you need to use a web server to manage the data transfer between the players.

  • dave1707dave1707 Mod
    Posts: 7,612

    @Ducky Thanks, I didn't think of multiplayer that way.

  • Posts: 1,976

    I believe @Zoyt is going to be making some tutorials for writing the server-side code for connecting clients and servers.

    You'd need a server, too, which you would have to buy.

    There are some Obj-C plugins for GameCenter which allows local multiplayer, I believe, but you wouldn't be able to test it in Codea, only in Xcode.

    And, for real multiplayer, across a good distance, not LAN, with a server, it would require pretty good server-side software to handle many requests quickly, the clients would be constantly requesting updates, and there would have to be tons of tweens for smooth interpolation between updates.

    It would be much easier if Codea had cough sockets cough.

  • Thanks for the responses guys.... It would be a turn based type game but like you said I think it will require servers, server software and all the rest.

    Do you know if any sites providing hosting services for situations as these?

  • Posts: 1,976

    You'll need to buy your own, I think. I believe sites like sell them. They're relatively cheap, but monthly. (By cheap I mean <= $10, maybe $2-$4.)

  • Or you could create your own server with your homecomputer, put a linux system on it, and make your own, but that's a little more complicated

    Also, it might not be a bad idea to look into Node.js, this is replacement for apache, and works with javascript, it doesn't use requests but sockets to send and recieve data, this would mean, using something as AJAX, but then in real time, AJAX still uses some kind of intervals to look for data

    Tho codea isn't suited for the use of node.js since the only way of making something come out or in from codea is still http requests, so the node.js wouldn't solve us being stuck to turn based games

    If only apple let us use the real power of our ipads ;)

  • edited November 2013 Posts: 2,042

    I think I saw a thread by @Vega on a Google solution. Google hosts the server for you and I believe it is free until a certain number of requests are made but I can't quite remember. That said, I have done turn based multiplayer locally by setting up a php server on my mac and using http.request, but it isn't ideal.

    EDIT: Here it is!

  • IgnatzIgnatz Mod
    Posts: 5,396

    There are also free servers out there, but the reliability may be suspect

  • Posts: 2,820

    @SkyTheCoder - It'll be a while until I get there, but yes, I hope to deal with multiplayer games. If I remeber correctly, someone posted an example for a multiplayer game earlier, but I can't find it.

  • Posts: 1,976

    @Zoyt Will it cover LAN and how to store and edit server files?

    @stevon8ter How do you make a server on Linux, and if I get a Raspberry Pi computer with Linux on it will it work?

  • @SkyTheCoder with your own server, you still will have to pay for a DNS, but you could also use it by calling it's IP directly, just google for Build your own linux server, I haven't done it myself yet, but probably will once I get my sister her broken computer xd

  • Posts: 2,820

    @SkyTheCoder - I haven't decided how far I'm going to go in my tutorials. I'll probably be moving to Unity and C# soon for the 3D version of my app, but I'll stick around on the forums, just not as much, so the amount of tutorials might get kind of limited. Anyone with a tutorials blog is welcome to pick them up from where I've left off whenever they want.

  • I think I'll ditch the two player thing and either go for 1 player vs the ai or two player on same ipad taking it in turns etc

    Are there any tutorials on turn based ai?

  • IgnatzIgnatz Mod
    edited November 2013 Posts: 5,396

    What do you need tutorials about?

    It might be easiest to make a player class that holds all the info about one player, and makes all the decisions about what that player does. Then your draw routine can simply loop through the players each turn.

    If you need help I can give you a rough outline.

  • Posts: 14

    Hey, I am looking around these fourms for the same answers!

    I am just a kid not an adult right now I have been saving money got over $100

    And planning to put enough work into my app for it to be like 1$

    Since I may get about 40 downloads a day Apple takes %40 of the income so I would maybe get about twelve dollars and that's enough to support the app server and everything becuase I am hoping for my app to multiplayer just like yours!

  • IgnatzIgnatz Mod
    Posts: 5,396

    Codea's socket code has proved unreliable, with big lags, so a multi player real time game (eg FPS) would be impractical. Turn based games may be OK, as they aren't affected so badly by lags.

    Maybe someone can get it to work reliably, but nobody has yet.

  • Posts: 815

    I had the idea to create a site each time you click a button, and display it, then you would have a real time updated text, that's already something.

  • Posts: 2,020

    Over-the-air multiplayer is hard to to get right even with game engines that have out-of-the-box support for it, and incredibly hard in Codea because of:

    1. needing 2 iPads,
    2. having to shuttle code back and forth between them,
    3. not to mention having to build code to address issues like latency etc from the ground up.

    No-one has managed it yet in Codea for real-time, action-based games. Or if they have, they've kept their code to themselves.

    Peer-to-peer turn-based (strategy, board games etc) is possible I reckon, but still very hard.

    Search the forum for "lua socket" and you'll get some code samples. I would not recommend it for beginners at all.

  • IgnatzIgnatz Mod
    Posts: 5,396

    And there is an unsolved problem with lag, which can be several seconds or more.

  • edited June 2016 Posts: 152

    Hi All,

    Our next game is a local multiplayer real-time strategy game for up to 4 players...

    Spent a lot of time creating a 'hardened' TCP layer and UDP game discovery system, and dealing with all the edge cases that go with it...

    Game event push is generally on a 1 second timer with queues etc. to smooth out lag, multiple messages queued and sent in one hit and then unmarshalled in one go for consumption...

    On most public Wi-Fi it works without a hitch, although some put different users on different sub-nets which is a pain ;)

    We use a GitHub Codea project to pull down changes to each of our devices and Working Copy to push changes to GitHub, then Fabric/Crashlytics to deploy to testers...

    Proper announcement imminent once we finish testing in the next few days...


  • IgnatzIgnatz Mod
    Posts: 5,396

    Great! Obviously, we'd love to see the multiplayer code if you're prepared to share it - but I realise it would have been a lot of work.

    Based on what you know, what do you think is the fastest (reliable) updating interval? One second delay is fine for strategy games, but not fast enough for (say) an FPS. I'm just wondering what the practical limit is.

  • Posts: 152

    Hi @Ignatz,

    Yes, considering how to open-source the TCP code, does somewhat depend if we can actually make some money ;))

    My dev partner who actually wrote all of this reckons we got up to 1000 messages/second on a decent network, and this is using a message protocol based on stringified tables which we then unmarshal back into objects using loadstring(), not the most efficient, but works a treat...

    So, with our reality goggles firmly attached we should be talking about a few hundred messages a second...


  • Posts: 2,020

    @brookesi awesome! I knew someone would crack it at some point... I'd also be interested in hearing any pointers you have for others interested in the multiplayer angle.

    Spent a lot of time creating a 'hardened' TCP layer and UDP game discovery system, and dealing with all the edge cases that go with it...

    Game event push is generally on a 1 second timer with queues etc. to smooth out lag, multiple messages queued and sent in one hit and then unmarshalled in one go for consumption...

    Sounds like it wasn't easy to get this going!

    Perhaps the socket thread here

    might be a good place to discuss?

  • Posts: 2,020

    Also cool to hear more people using Working Copy. If you're on Twitter, tweet the Working Copy dev about your experiences using it, he'll retweet. And tweet TwoLivesLeft too of course!

  • Posts: 152

    Hi @yojimbo2000,

    Working copy is very good, I will Tweet like a happy birdie...

    Will try and get my co-developer to contribute a post on the socket thread with his experiences creating the API...


  • IgnatzIgnatz Mod
    Posts: 5,396

    That would be fantastic, @brookesi - multiplayer capability will add a lot to Codea.

  • All of this might be easier if you could somehow connect to each other's devices with Bluetooth and send information between each other when it's necessary, with no central server necessary to handle the information.

  • Posts: 2,020

    All the sample code on the multiplayer thread is connecting to other devices directly, using sockets. No one is trying to go via a server.

  • Posts: 152

    Hi all,

    OK, after a long hiatus we are hoping to release our multiplayer game next week...

    We have finally fixed the IPv6 connectivity so our network code is now protocol-agnostic, the IPv6 UDP broadcast for game discovery was the hardest one to crack...

    (Apple now require all apps to support IPv6, and luckily you can turn your Mac into an IPv6 wireless router which makes ife easier for testing!)

    We are going to try and 'librify' our network layer at some point and make it available somehow, will keep the community posted...


  • Posts: 2,020

    Awesome work!

  • Posts: 815

    After this one, it will be my turn to go making a multiplayer game. I have prepared some code for it. But dome questions: Have you made the connecting in a library, or how?

  • Just for another take on this: if you haven't already invested a lot of time in Codea development, you might want to look into Apple's own Game Center service. It lets you do both turn-based and real-time multiplayer without a server. It's not perfect but it's pretty good. And learning to program direct iOS code is a lot easier now with Swift. Not Lua-level easy but not a ton harder.

Sign In or Register to comment.