Hi everybody,
I am busy with the Highscores tutorial with dreamlo on youtube:
.
I have a little problem with displaying the username in the highscorelist.
The usename is a string but when my username consist of two words separated by a space (first name and last name), a ‘+’ sign is placed beween the two words when it is displayed in the scoreboard.
I think it’s in this code:
IEnumerator UploadNewHighscore(string username, int score) {
WWW www = new WWW(webURL + privateCode + "/add/" + WWW.EscapeURL(username) + "/" + score);
yield return www;
if (string.IsNullOrEmpty(www.error)) {
print ("Upload Successful");
DownloadHighscores();
}
else {
print ("Error uploading: " + www.error);
}
}
Does anybody knows where this ‘+’ sign is coming from and how I can replace it by a space?
I think it’s because you’re using it with escapeURL. Certain chars get changed when you use that to make them URL compatible. I bet if you debugged it it might show a + (maybe, this is a guess)
If you are displaying it local, just use the string.replace call to replace + with a space.
String userName = "My+Name";
userName= userName.Replace('+', ' ');
Code should do it, but didn’t test it, note it’s a reference point since you’ll have to replace the value depending on where your username comes from.
Unity also provides an unEscapeUrl that may just reverse the name Unity - Scripting API: WWW.UnEscapeURL
It’s from escaping the URL. Since spaces aren’t used in URL’s, + is one of two standards for escaping it (the other being %20). And you do, absolutely, need to escape the url before you submit it - otherwise you’ll be leaving your game open to both bugs and security flaws if players start using weird characters in their names.
What you need to do is to un-escape the returned text before you display it on the scoreboard.
Ok, I understand now.
Thanks for reply.