- Home /
Retrieving online highscores (following a guide)
I'm following this guide: http://wiki.unity3d.com/index.php/Server_Side_Highscores
I can post to my server just fine and see the scores in there, but retrieving them isn't working.
I have adapted the GetScores code as follows:
private bool scoresDisplayed = false;
private string highscoreURL = -omitted-;
private string scores;
void OnGUI()
{
if(GUI.Button(new Rect(500,500,150,50), "Leaderboard")) {
scoresDisplayed = true;
}
if (scoresDisplayed) {
GUI.Box(new Rect(800,500,150,50), scores);
StartCoroutine(GetScores());
}
}
IEnumerator GetScores()
{
scores = "Loading Scores";
WWW hs_get = new WWW(highscoreURL);
yield return hs_get;
if (hs_get.error != null)
{
scores = "There was an error getting the high score: " + hs_get.error;
}
else
{
scores = hs_get.text;
}
}
The box is displayed when I click on the Leaderboard button and says "Loading Scores", but nothing then happens.
I have tried both versions of the php code provided in the guide for display.php but that doesn't make a difference, and I know my database details are okay because it works for posting scores.
I did have an error in the console on an attempt as follows, and it came up 52 times, but don't know what it means:
null != m_thread
unityengine.www:.ctor(string)
Any pointers as to what I might be doing wrong will be appreciated. If you need to see more code, just ask, although I think this is all that's necessary along with the linked guide.
Hello! I'm just trying to set up a leaderboard to my game like you with the same guide,but i have some questions and i can't understand some thinks can you give me a conntact with you and could you help me wiht this please ;(
Answer by chris_taylor · Feb 28, 2014 at 06:05 PM
you are calling StartCoroutine(GetScores()); everyframe witch means your starting a download and also setting scores to loading scores every frame
try this
if(GUI.Button(new Rect(500,500,150,50), "Leaderboard")) {
scoresDisplayed = true;
StartCoroutine(GetScores());
}
if (scoresDisplayed) {
GUI.Box(new Rect(800,500,150,50), scores);
}
Your answer
Follow this Question
Related Questions
Saving a leaderboard using PHP and C#. 2 Answers
Writing an array to a txt document and send it to my server 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers