Hello
I set up server-sided hiscores found in Unity’s wikipedia earlier today, but I don’t get it how to use the postScore function which would add the username and scores to my database…
here’s the script that i use from wiki:
private var secretKey="deletedthis"; // Edit this value and make sure it's the same as the one stored on the server
var addScoreUrl="deletedthis";
var highscoreUrl="deletedthis";
function Start() {
getScores();
}
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.
var hash=Md5.Md5Sum(name + score + secretKey);
var highscore_url = addScoreUrl + "name= " + WWW.EscapeURL(name) + " &score=" + score + "&hash=" + hash;
// Post the URL to the site and create a download object to get the result.
hs_post = WWW(highscore_url);
yield hs_post; // Wait until the download is done
if(hs_post.error) {
print("There was an error posting the high score: " + hs_post.error);
}
}
// Get the scores from the MySQL DB to display in a GUIText.
function getScores() {
gameObject.guiText.text = "Loading Scores...";
hs_get = WWW(highscoreUrl);
yield hs_get;
if(hs_get.error) {
print("There was an error getting the high score: " + hs_get.error);
} else {
gameObject.guiText.text = hs_get.data; // this is a GUIText that will display the scores in game.
}
}
So how do I use the postScore function to add scores and name to my database? For e.g. I add gui button for “submit” and what do i write so it would send the stuff to my database?
I’ve done everything else and it shows the names scores well etc., just can’t figure out how to record them >.<
thanks