Multiplayer game

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
terumi
Posts: 6
Joined: Fri Mar 25, 2011 4:19 am

Multiplayer game

Post by terumi »

Hello everyone.

After watching the tutorials named "Browser Based MMORPG" I realized that the subject of making the game actually multiplayer wasn't covered.
I'm trying to build a simple dueling game, and I want to have two (or more) players logging in an "arena" in order to fight.
The game, I reckon, has to be turn based but I cannot find a solution about giving each player the oportunity to know whos turn is.
So my questions are:
-Is there an event system in php?
-Is such thing as shared session variable?
-Is it possible to do a "whos turn is" check without some cron job or a loop that checks if the players turn is finished?
-Is it a tutorial about the multiplayer subject?

Thank you very much.

Terumi.
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Multiplayer game

Post by hallsofvallhalla »

-Is there an event system in php?
if you write one yes.
-Is such thing as shared session variable?
not really unless you store the variable in the database and then check it on page load or you use Ajax.
-Is it possible to do a "whos turn is" check without some cron job or a loop that checks if the players turn is finished?
this would require ajax or a page refresh
-Is it a tutorial about the multiplayer subject?
yes, while i have not added true multi-player or PVP it is quite simple to make it happen. The game in itself is mult-player just not so interactive. I am working on tutorials to make it so .
terumi
Posts: 6
Joined: Fri Mar 25, 2011 4:19 am

Re: Multiplayer game

Post by terumi »

First of all thank you for your time to respond, make all these tutorials, interact will all us...
-Is it possible to do a "whos turn is" check without some cron job or a loop that checks if the players turn is finished?
this would require ajax or a page refresh
Should the ajax performing a loop to check the states or is there a more "elegant" way of doing it?

Thank you again.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Multiplayer game

Post by Jackolantern »

It depends on what you want it to do. The more real-time you want it to be, the more you will have to rely on short-timered AJAX loops (aka "polling") to check for changes. However, this has many downsides, such as the amount of wasted server CPU power and bandwidth. There are some other, more advanced options such as Comet, web sockets or an RIA platform, but those both require dedicated server software outside of the web server software.
The indelible lord of tl;dr
terumi
Posts: 6
Joined: Fri Mar 25, 2011 4:19 am

Re: Multiplayer game [SOLVED]

Post by terumi »

I used polling to check if a text file (containing a single status code) has changed.
As the game is a turn based game, I hope that the bandwidth consumption is minimal.
Thank you for your insights.

:)
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Multiplayer game

Post by Jackolantern »

It just takes some tweaking. You want to find that sweet spot where you are waiting as long as you possibly can in each polling cycle. Just an extra half a second can mean huge bandwidth savings if your site becomes popular.
The indelible lord of tl;dr
terumi
Posts: 6
Joined: Fri Mar 25, 2011 4:19 am

Re: Multiplayer game

Post by terumi »

Nah.. I'm into learning rather that being a succesfull/ rich/ popular game designer.

:)
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Multiplayer game

Post by PaxBritannia »

I can't express how much I adore the sentiment you just conveyed. :D

pax.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Multiplayer game

Post by Jackolantern »

Even if you don't make any money, eventually it is nice to have something you make become semi-popular to keep you moving forward. Ask Halls about that ;)

EDIT: Plus, writing web software for popularity (aka "scalability") is just considered good practice, since your creations will break after they receive so much traffic at once if they are not. Regardless of what you are developing for, it is always a good idea to build your applications to be as robust as possible.
The indelible lord of tl;dr
User avatar
Callan S.
Posts: 2043
Joined: Sun Jan 24, 2010 5:43 am

Re: Multiplayer game

Post by Callan S. »

Yeah, it depends on what your trying to learn. I'd say the most common practices are those which optimise like Jack says - so if your trying to learn the common practice, that's what you'd be learning, even if you never need it.
Post Reply

Return to “Beginner Help and Support”