Been trying to implement a highscore system, and I was just testing/starting out with the standard highscore found in the wiki.
http://www.unifycommunity.com/wiki/index.php?title=Server_Side_Highscores
Been having issues though, it wouldn't add scores to the database. Using identical php scripts from the wiki except for own values and rewrote the javascript to c#.
IEnumerable PostScore(string username, int score)
{
var hash = Md5Sum(username + score + _secretKey);
var highscoreUrl = _addScoreUrl + "name=" + WWW.EscapeURL(username) + "&score=" + score + "&hash=" + hash;
var hsPost = new WWW(highscoreUrl);
yield return hsPost; // Wait until the download is done
if(hsPost.error != null)
{
print("There was an error posting the high score: " + hsPost.error);
}
}
Never worked. I checked to make sure md5 matched, i printed off the url and manually used it and it all worked fine, but when that script runs it never added a score to the database.
I finally decided to test it without the yield
void PostScore(string username, int score)
{
var hash = Md5Sum(username + score + _secretKey);
var highscoreUrl = _addScoreUrl + "name=" + WWW.EscapeURL(username) + "&score=" + score + "&hash=" + hash;
var hsPost = new WWW(highscoreUrl);
}
Works fine, adds the score to the database but I'd obviously like the added functionality and options of using the yield so could anyone explain to me why it's not working?