I'm pretty noobish at web coding / webdev. I'm trying to figure out how I could write a browser game using only JavaScript on the client-side (ie. no browser plug-ins). But I'm stuck on figuring out how to handle everything server-side.
The only thing I've thought of is to store everything in a SQL database, and just have the AJAX post some information to a PHP file that will take care of everything. However, I'm wondering if there are other, better ways of doing this that I can't think of. I'm also not sure about handling concurrent players because I haven't done very much with databases before, so I'm not sure whether I'll have to worry about race conditions or something.
It's not much different than any other kind of client-server game, so just define the requests, write the client, write the server which maintains the internal world state, maybe persist it somehow (you mention MySQL, but any kind of persistence can be used). The server-side language can be anything as well, why choose PHP?
Insisting on doing everything on a single page with AJAX is probably misguided. It depends on the kind of game, though.
Name:
Anonymous2010-05-08 14:16
SQL [...] AJAX [...] PHP
You do not need any of those things. Data can be stored in any format, not just in an SQL database; AJAX is not necessary if you do things correctly; any scripting language can be used (not just a bastardised macro language). Consider a javascript platform game:
- The entire thing could be one (let's say Perl) script that generates the page, including (dynamically) all <script ... /> tags necessary
- Global / engine code can be kept in static .js files.
- Level data can be kept in plain text files, or however you need. They could perhaps be parsed to generate javascript containing global variables, like tiledata
- Per-user persistent data can be kept in the same way, and accessed with GET parameters or something.
- Levels are specified in GET also.
- On completion of a level, a simple hypertext link appears (through javascript) that simply links to "game.cgi?level=" + (level + 1)
It's not difficult to avoid using ENTERPRISE stuff like AJAX when you don't need to.
Name:
OP2010-05-08 15:44
>>6 - On completion of a level, a simple hypertext link appears (through javascript) that simply links to "game.cgi?level=" + (level + 1)
Not sure if I can explain this right. Essentially I want all of the game text (messages from the game, such as information about where you are, chat from other players, etc.) to appear in one edit box, streaming in real-time like IRC rather than just refreshing the page once every minute (like a shoutbox) or making the user click a link to go to the next page as you suggested. Which is why I came up with AJAX, because I know I could do that with AJAX. I don't know that I could do it any other way, but I'll take any suggestions.
>>2 The server-side language can be anything as well, why choose PHP?
Because I'm familiar with it. Crappy reason, I know. I should probably figure out a different language I could use for server-side scripting before I get into this.