Tutorial: Online Multiplayer with PodSixNet

Post your own tutorials, guides and demos.

Post » Tue May 04, 2010 3:24 pm

Sprite index.

Isn't that "for each" + loopindex = to 0, 1, 2, 3, etc same thing? Unless I'm missing something.
B
2
S
2
G
4
Posts: 259
Reputation: 1,968

Post » Tue May 04, 2010 7:32 pm

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!!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Thu May 13, 2010 4:47 am

:idea:
<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?
B
1
G
2
Posts: 5
Reputation: 635

Post » Thu May 13, 2010 10:04 pm

[quote="Ghambit":2zgvicoj]There's more to is obviously and I'm rambling so I'll stop here. Anyways, is this a doable plan?[/quote:2zgvicoj]
That was quite the brain dump. :wink: 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.

[quote="Ghambit":2zgvicoj]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.[/quote:2zgvicoj]
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.

[quote="Ghambit":2zgvicoj]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... [/quote:2zgvicoj]
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.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Fri May 14, 2010 3:34 am

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 -
B
3
S
1
G
2
Posts: 16
Reputation: 857

Post » Fri Jun 04, 2010 4:11 pm

[quote="scidave":mn65elca]Thanks everyone! I really hope this will get more people to try Python and Construct.
If you can't do that then multiplayer games are impractical for anything more than a 2-4 person game. [/quote:mn65elca]

so we still can't do a 8-16 players games?

only small games like chess, monopoly, pong, etc?
B
2
G
3
Posts: 18
Reputation: 886

Post » Fri Jun 04, 2010 9:22 pm

[quote="Bonecrusher":2wvzrgyu]so we still can't do a 8-16 players games?[/quote:2wvzrgyu]

You are confusing two separate things here. You can make a thousand player game if you have the bandwidth and computing power. There is no inherent set limit on the number of players in PodSixNet. The example game in the tutorial is a 2-10 player and could easily be a 20 player just by changing 1 line of code. There may be some limit with Construct itself, but I have yet to run into one.

I was referring to if someone made a network plugin they would need to add sprite indexing. It is unrelated to Python.

[quote="Bonecrusher":2wvzrgyu] only small games like chess, monopoly, pong, etc?[/quote:2wvzrgyu]
You can make them as big as performance/bandwidth allows.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sat Jun 05, 2010 12:46 pm

hmm ok thanks
B
2
G
3
Posts: 18
Reputation: 886

Post » Mon Jun 21, 2010 10:43 pm

I'm pretty new to Construct, though I've done a lot of coding. Very little in Python though.

I did get these tutorials working, but I have a question.

In order to get them working, I had to export the server program to an EXE before I could run a client on the same computer. Construct says that I already have a preview running, and I need to close it first if I try to run both otherwise.

Is there a way around this, or is this the intended usage of the server program?

Thanks :)
B
3
G
2
Posts: 35
Reputation: 745

Post » Tue Jun 22, 2010 1:30 am

[quote="Zaaephod":uu81php4]I had to export the server program to an EXE before I could run a client on the same computer. ..... Is there a way around this, or is this the intended usage of the server program?[/quote:uu81php4]

I ran into the same issue. I did the same thing, either ran the server in Construct and exported the client to EXE or ran the client in Construct and exported the server to EXE. I couldn't do both through the Construct IDE. So it is expected behavior and I didn't investigate further to see why.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

PreviousNext

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests