0 Favourites

Tutorial: Online Multiplayer with PodSixNet

This forum is currently in read-only mode.
  • This tutorial shows how to make network programs, and online and LAN multiplayer games using Python and the PodSixNet (http://mccormick.cx/projects/PodSixNet/) library.

    The tutorial walks through setting up your environment,distributing your game, using the PodSixNet library, and then reviews the .cap files of several example network programs. The games include a chat program, network pong, and a 2-10 player dungeon escape game. Latency is briefly addressed and some techniques to reduce lag are mentioned.

    Download link (need Construct .99.84 or later)

    http://www.box.net/shared/1ukq09e6e1

    <img src="http://i43.tinypic.com/153ma2p.jpg">

    <img src="http://i42.tinypic.com/657hbc.jpg">

    Users are assumed to know a little bit about Construct and should already have done the Ghost Shooter tutorials at the minimum. Only minimal prior knowledge of Python is necessary. Enjoy!

  • Wow, The long awaited tutorial and it seems to be well worth the wait. I have not sat down and read it all as i want to. Currently doing college material but i will definatly look at this after with a full review. So far it looks really kick ass.

  • Freakin' ace. Haven't looked through it all yet, been real busy, but I'm sure it's all class.

    Thanks for making the tutorial Dave. I really appreciate it.

  • AWESOME!!! From what i have looked at so far it all seems very well written and easy to follow. Excellent job

  • Yay! thanks man this looks great!

  • sooo ... when is this going to become a plug in? =P

    Great tutorial by the way. I haven't read through it in detail but the proof speaks for itself!

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Woah, this is really awesome. Definately will look into this, even if I have no clue about python.

  • sooo ... when is this going to become a plug in? =P

    Great tutorial by the way. I haven't read through it in detail but the proof speaks for itself!

    It is Python. It cannot be made into a plugin like this.

  • > sooo ... when is this going to become a plug in? =P

    > Great tutorial by the way. I haven't read through it in detail but the proof speaks for itself!

    >

    It is Python. It cannot be made into a plugin like this.

    Never doubt, just because it hasn't been done before doesn't mean it can't be!

    Plus, I do know that it's Python, I was just making a joke ... thanks for ruining it. haha

  • Thanks everyone! I really hope this will get more people to try Python and Construct.

    sooo ... when is this going to become a plug in? =P

    I recognize the humor. This functionality would make for a sweet plugin. As crazy as it sounds Python is actually BETTER than a plugin (assuming the PV and behavior access is fixed in Python). The reason is that Construct does not have access to sprite indexing (the ability to reference a sprite instance by index), but Python does. For example, sprite[0].X would access the first instance's X location. If you can't do that then multiplayer games are impractical for anything more than a 2-4 person game. If someone writes an online plugin, they also need to add support for sprite indexing.

    It is Python. It cannot be made into a plugin like this.

    Technically, you could make a plugin based on this library by using Python embedded in C++. Now, would someone actually want to do that? Probably not, they would just write it all in C.

  • Sprite index.

    Isn't that "for each" + loopindex = to 0, 1, 2, 3, etc same thing? Unless I'm missing something.

  • It isn't clear that your example could achieve similar results. For example, how would you do something like this?

    Assume you have 100 instances of Sprite each representing a networked client's player. Each player gets a global variable "myNumber". Assume that for one player, his myNumber = 88.

    In Python, to set his sprite to a new position:

    Sprite[System.globalvar('myNumber')].SetPosition(x,y)

    Your method in events has to directly access the right sprite instance, you can't loop through instances up to 88 or pick based on private variable. If you can, then many people including myself would be very interested!!

  • <forgive me, for I are newb>

    In the case of a simple turn-based game. Is it not possible to parse data from a read-only chat channel? For instance, you could have your normal chat channel that people talk from and then another channel (read-only or invisible) devoted to the "system" or "combat," etc.

    You have strings in these channels representing all relevant data (object positions, states, etc.). Each client subscribed to the channel would then be able to draw the gamespace dependent on said channel(s).

    At each player's end of "turn" their channel(s) would update (pump) to the server, which would trigger everyone else's client to update... and on and on.

    A smart cookie would make multiple channels devoted to certain objects. For instance you'd have one channel devoted to chargen, another to object location, another for combat, another for map states, etc. This way you're not parsing from one huge string every turn and only call on what's needed... as well, this allows for turns to be "interrupted" when viable per the game's rules ("attacks of opportunity", "assisted actions," "overwatches," and so on.) In this way you could moreso look at a turn as an "action." For instance, it's PlayerA's turn and he moves his character 5 spots, then the server pumps the object locations channel, clients update, events activate, etc. Then PlayerA fires his weapon and the cycle continues until he's taken all of his actions. Then his turn is over and the next Player goes through the same routine. In this way, other players can more adequately keep track of what's going on and you dont have to worry about any timing issues (e.g. if you were to do one global (pump) at every endTurn all the clients would simply "blink" and the other players would be like wtf? You'd also have to code each game element to sift through a long, complex chat string - which sux).

    Periodically the server will autopump all channels to create a saveState in case of connectivity loss. This saveState would remain in the remote server and/or each client. This way, games that arent completed can be finished later. Since the channel data will be system tagged, upon restarting the game you can have the game only generate the most recent gamespace and ignore the rest.

    And on and on and on.

    Basically, this whole idea leverages this simple code:

    connection.Send({?action?: ?action_name?, ?tag_name?: tagdata})

    And then obviously the similar code from server to client.

    Data is data... and in a TurnBased game we dont need to worry as much about floods and latency so why not just use the simple chat server as our window to multiplayer gaming?

    I'm weak with Construct since I just started and my programming skills are sophomoric so I'm not entirely clear on how it'd effect the build, but the goal is definitely to make it as simple as possible. Ultimately I'd like to dev. the game for "Hot Seat" and be able to easily add network function with minimal code. I guess it'd be as simple as just adding connection.Send({?action?: ?action_name?, ?tag_name?: tagdata}) after each action. The game would be "globalized" so the server essentially wouldnt care (aside from chat) who did what, but clientside the game would lock you out from manipulating the gamespace if it wasnt your turn per the rules.

    There's more to is obviously and I'm rambling so I'll stop here. Anyways, is this a doable plan?

  • There's more to is obviously and I'm rambling so I'll stop here. Anyways, is this a doable plan?

    That was quite the brain dump. But yes, everything you are describing sounds very doable. If fact, if you were to look closer at the tutorial series all of the games (pong and dungeon escape) are essentially the same as the chat client and chat server.

    Is it not possible to parse data from a read-only chat channel? For instance, you could have your normal chat channel that people talk from and then another channel (read-only or invisible) devoted to the "system" or "combat," etc.

    Technically, you only have one client "channel" in podsixnet but you can have as many ConnectionListener and as many actions as you want. When you refer to "channels" here I think you really mean actions.

    A smart cookie would make multiple channels devoted to certain objects. For instance you'd have one channel devoted to chargen, another to object location, another for combat, another for map states, etc. This way you're not parsing from one huge string every turn and only call on what's needed...

    Yep, this all makes sense.

    I would probably use a simple state machine on the server and then just select the next client. The way I see things working is:

    0. Server issues a "start turn" action to the next client. The client enables it's turn group.

    1. Client does their stuff via different actions (object location, combat, etc). Once they are done they issue an "end turn" action. The server can also forcefully end the current turn by its own "end turn" action if the client is taking too long or what ever reason. This then turns on a group dedicated for processing user input on that client.

    2. While a particular client is working all other clients see player updates but they can't process user input. The server then picks the next client and the process continues.

    It sounds like you have a good idea how this would work. Turn-based should be relatively straightforward with Construct, Python, and PodSixNet.

  • Great work scidave!

    I hope someday improve my UDP netcode... I'm on another project right now and besides that, i have a work hehe.

    Python scripting capabilities is really a great way to improve Construct.

    • FRP -
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)