That’s right - you’ll definitely need some server side scripting, and things get much easier if you use a database as backend (of course, you could do flat-file stuff, too - but I just wouldn’t like to do that).
You could take a look at my TRaceON high scores. It’s a bit involved since it’s based on DotNetNuke and I have different kinds of high scores - but I like the flexibility I have with this approach.
The components I needed to create for this:
In the Game
A little UI that allows players to say “I want to save my time to the server” (only when they’ve logged in on the Website before starting the Web player)Currently, there’s no in-game high score list (could be added, though - just needs a little UnityGUI magic plus getting the stuff via the WWW-class plus one or two more methods in my “WebService”
)
On the Web Frontend
“Web Service” (HTTP-GET / HTTP-POST parameter based; simple, no XML involved) which accepts high scores from players; if in game high scores are needed, this would need to be extended to also create some sort of comma-separated list that’s easy to parse in the playerA simple little DotNetNuke module that allows the Web page visitor to select the “type of high score” and then lists the data from the database
In the database
Two tables: One for the actual high scores, and one to store different types of high scores (e.g. shortest time level 01, shortest time level 02, shortest overall time; longest time level 01 etc., or “Score” - whatever I could come up with)Three Stored Procedures: One to store the player time / score / whatever, one to get the types (to create a drop-down list), and finally, the one that returns the actual high scores
The nice thing about having high score types in an own table in the database is that if I want to add a new type of highscore that’s based on data that’s already in the database, I can simply add that new type, and change the stored procedure returning the table of high scores - and that’s it. It also makes this comparatively easy to extend the system to be able to store high scores of different games in the same high score table. So this gives me a lot of flexibility (which I like), but it adds a bit of complexity (which doesn’t bother me
).
The actual implementation is not something ready to be shared, simply because the implementation is integrated with the whole system and it’s work in progress … and it’s not designed to be general but instead with a strong focus to perfectly fit my own needs. There’s stuff like player management, which relies both on the DNN user database and my own player database etc. - also, it’s ASP.NET based (which is less popular than PHP, I guess - especially if you want to have it hosted somewhere)…
But I guess the concepts should be useful…
For a simple system, I guess all you need is a simple table (PlayerName, Timestamp, Score), and then do INSERTs and SELECTs in the Web frontend (the Web front end would simply accept PlayerName;Score from the game, which would be sent via the WWW class). So I guess if you find the simplest PHP/SQL tutorial available, this will give you enough to implement the server-side stuff easily on your own.
One pattern I would definitely recommend for things like this is having some sort of HttpHandler (don’t know if that exists in PHP - if not, simply think of it is one page), that has one parameter “command”. That way, you don’t have to write one separate page for each command (save highscore, get highscore etc.), but instead can branch in a single “command handler” page according to your needs. Of course, you’d probably still want to have a separate (Web-GUI oriented) page for displaying those high scores on the Web.
Sunny regards,
Jashan