- Home /
Server Based High Score - issues with adding new score
Hi,
I'm following this tutorial, having no prior experience with networking, databases etc.. http://gamedev.stackexchange.com/questions/53566/server-based-high-scores
I almost got it working, except for the running the addscore.php script. Here's my slightly modified PostScores() coroutine:
public static IEnumerator PostScores(string name, int score, int rank)
{
//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.
string hash = Utility.Md5Sum(name + score + secretKey);
string post_url = addScoreURL + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&rank=" + rank + "&hash=" + hash;
print (post_url);
// Post the URL to the site and create a download object to get the result.
WWW hs_post = new WWW(post_url);
yield return hs_post; // Wait until the download is done
if (hs_post.error != null)
{
print("There was an error posting the high score: " + hs_post.error);
}
}
So, the interesting part is that when I print the url thing and copy-paste it in my browser it works fine. I can see new entries added in my database and then the other script reads them correctly in my game. So, I suspect it's these lines that seem to be rogue:
WWW hs_post = new WWW(post_url);
yield return hs_post; // Wait until the download is done
This is all new stuff for me - I don't even understand the coroutines fully. I also get no errors, so no clue what's wrong. I can't be asking my players to copy-paste the generated url in their browser every time, can I? ;) :D
Thanks in advance,
Answer by JuliuszK · Jan 21, 2017 at 05:20 PM
OK, so the problem was, that my object calling that coroutine was getting destroyed in the same frame, as I was loading a new level. I just moved stuff around, so the coroutine is getting called from a persistent object instead.
Your answer
![](https://koobas.hobune.stream/wayback/20220612105054im_/https://answers.unity.com/themes/thub/images/avi.jpg)