WWW makes app freeze

I’m doing a WWW call to get an online high score table. It’s taken from the high score example that everyone seems to throw around. It works perfectly well in the editor, but when I build it on the iPhone it freezes when called. Can’t quite figure out why, maybe someone has a good insight into this? Thanks!

// Get the scores from the MySQL DB to display in a GUIText.
function getScores() {
    scoreText = "Loading Scores";
    hs_get = WWW(highscoreUrl);
    var timeOut = Time.time + 10;
    while (!hs_get.isDone) {
    	if (Time.time > timeOut) {
    		break;
    	}
    }
    if(hs_get.data) {
        scoreText = hs_get.data; // this is a GUIText that will display the scores in game.
    } else {
        scoreText = "Could not download high scores";
    }
}

your call makes it freezing because you loop till the download has happened. the loop itself isn’t the problem but the fact that you never yield and thus block the rest of the application with this :slight_smile:

As it works in the editor, make sure you have your iPhone wi-fi turned on. Also check if the hs_get gives any error by using hs_get.error

You guys always rescue me. :slight_smile: Tossing a teensy yield in there did the trick.