Hi guys Can anyone help me out ? I'm trying to implement the mySql/ php www highscores scripts ... I know this is dumb but I'm just not getting where I declare the "name " of the current player and the "score" .. or maybe I'm just not getting how the JSscript HSController actually works .. I think the url path is correct and the mySql data base table appear to be right ... I've attached the HSController script to a guiText gameObject and when I run it .. it displays the string "loading scores" ... and then does nothing .... I'm assuming that's because there's nothing to display yet ... so where and how do I declare what the players name and score is? Is it within function postScore(name, score) { //This connects to a server side php script that will add the name and score to a MySQL DB. // Supply it with a string representing the players name and the players score.
I don't think there is anything subtle about the postScore method - it's more likely that something else is wrong. Try accessing your URL from a web browser. If it works OK and the database gets updated, then some other aspect of the connection is at fault. If you are using a web player, then make sure the .unityweb file is in the same folder as the PHP page that activates the database (or maybe this restriction has changed in Unity 2.0?) If you can view the web server's access log, then you can check that the server has received the message from the Unity game. If it hasn't then the most likely problem is a dodgy URL - you may be able to retrieve the incorrect URL from the log and check it for capital letters, etc. Failing that, check that the score and name data are being sent correctly. Also, if you are using the MD5 hash thing, then check that it is being handled correctly (basically, just comment out the MD5 checks in the PHP script and see if it works without them).
Yeah ... I got it all going ... I neglected to include the Md5 script to handle the encryption .... it all seems to be working now ... I'm using it for a racing style game .. I need to rethink how I'm using though .... I want to generate a list of scores for the different games/tracks ... at the moment there's only two tracks, but there could be more tracks and also different game play modes ... you know like speed, pickups, stunts etc. ... so I'm thinking about how to implement a highscore system that can reflect the different score lists ... so I guess multiple mySql tables? or more columns within the tables with the added variables ... Track1, Track2, GameStyle1, GameStyle2 etc. and then call up the scores via a script that can read those values ... Code (csharp): if gameStyle1 == 1 { doSomethingLikeLoadThisScore; } else { dontLoadThatScore } or something to that effect, although as I'm not really familiar with the process ... I'm sure I'll have to do a bit more reading ... still ... it's essentially working and it's really just a matter of adapting it to suite the requirements of the game! How did you go with your attempts Hai_ok? Cheers!
Yeah, got mine working. I was just trying to find out if I should try to write a tutorial, or if you got yours working. You should definitely use a separate table for each mode score list. You should try something like: Code (csharp): var highscore_url="http://www.my-site.com/highscores.php"; function get_score(mode : String, name : String, score : String){ var form = new WWWForm(); form.AddField( "mode", mode ); form.AddField( "name", name ); form.AddField( "score", score ); var download = new WWW( highscore_url, form ); yield download; if(download.error) { print( "Error downloading: " + download.error ); } else { // show the highscores print( download.data ); // you can send download.data to a string handler to display your high score list } } So depending on which mode you send to your php, it will build the SQL query to read from that table in your database. Then in your PHP, use ORDER BY 'score' in your SQL query. Then it will either be in ascending or descending order. You can further use the 'name' value above as a way to change the color of the player's name when they look at the scores. That way it will be easier to see themselves wherever they appear in the score list. I hope this helps! Where to learn more (cause it's where I got my answers): SQL: http://www.w3schools.com/sql/sql_intro.asp PHP (Strings): http://www.tizag.com/phpT/strings.php Unity High Score (WWW) Page: http://unity3d.com/support/documentation/ScriptReference/WWW.html
Also, you should be sending the current score (adding it to the database) and getting the high score list at the same time. You can easily do all this in a single php page, print it all to the screen and parse it with Unity.
Thanks for that Hai_ok! Probably a more in depth tutorial wouldn't go astray ... I know it would have helped me out ... Cheers
If the information you store for each mode or track is very different then it might well be easiest to use a separate table for each. However, if the score data is essentially the same each time then you might consider just adding fields to your existing table. Say if you have several tracks in your game, you could add a field called "track" to the scores table. Then, in the SQL, you would just add an extra condition to the WHERE clause:- Code (csharp): SELECT * FROM scores_table WHERE (score > xxx) and (track = 2)... (Of course, the value of "track" would come from the web form in practice.)