Hi I’m following a tutorial online to figure out how to compile a list of high scores in a game. I understand most of this code following along but the only section that I can’t wrap my head around is all the code under the FormatHighscores method. It’s very confusing to me and I’m just learning how to do this.
I understand why that method is being used, but I don’t understand the lines of code within it that makes it do what it does.
If anyone can give me a brief explanation if possible, that would be great. The vid doesn’t explain much during that part.
Thanks!
const string privateCode = "YaCRIoQQDkG39N9_tr3CygJgI08xYI2EylCY7MXRXoA";
const string publicCode = "599be7366b2b651a6cba683";
const string webURL = "http://dreamlo.com/lb/";
public Highscore[] highscoresList;
void Awake()
{
AddNewHighscore ("Sean", 10);
AddNewHighscore ("Lucas", 8);
AddNewHighscore ("Austin", 2);
DownloadHighscores ();
}
public void AddNewHighscore (string username, int score)
{
StartCoroutine (UploadNewHighscore (username, score));
}
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!");
}
else
{
print ("Error Uploading: " + www.error);
}
}
public void DownloadHighscores()
{
StartCoroutine ("DownloadHighscoresFromDatabase");
}
IEnumerator DownloadHighscoresFromDatabase()
{
WWW www = new WWW (webURL + publicCode + "/pipe/");
yield return www;
if (string.IsNullOrEmpty (www.error))
{
FormatHighscores (www.text);
}
else
{
print ("Error Downloading: " + www.error);
}
}
void FormatHighscores(string textStream)
{
string[] entries = textStream.Split (new char[] { '
’ }, System.StringSplitOptions.RemoveEmptyEntries);
highscoresList = new Highscore[entries.Length];
for (int i = 0; i < entries.Length; i++)
{
string[] entryInfo = entries *.Split (new char[] { '|' });*
-
string username = entryInfo [0];*
-
int score = int.Parse (entryInfo [1]);*
_ highscoresList = new Highscore (username, score);_
print (highscoresList .username + ": " + highscoresList .score);
* }*
* }*
}
public struct Highscore
{
* public string username;*
* public int score;*
* public Highscore(string username, int score)*
* {*
* username = username;
score = score;*
* }*
}