Hello, I have a good high score system working which does also upload and download perfectly to and from the database. I now want to show the Level number that the player managed to reach. If they finally get GameOver, it add’s their Username, Score and LevelNumber to the Database. So far, Username and Score is working.
I have NO errors in the code and it shows me the level number in game successfully when it loads up the leaderboards and even puts the level number.
The only part that is NOT working is that it doesn’t upload the level number to the database and just shows Name and Score. It seems like the entries length is maxed out to two? That’s my guess…
[50006-score.png*_|50006]
As you can see, I want to add a third column which is called ‘Level’. I am very very new to all this database stuff, and only started around a week ago. If you are willing to educate me on this subject, that would be awesome!
using UnityEngine;
using System.Collections;
public class HighScores : MonoBehaviour {
const string privateCode = "//SECRET";
const string publicCode = "//SECRET";
const string webURL = "http://dreamlo.com/lb/";
public Highscore[] highscoresList;
static HighScores instance;
DisplayHighscores highscoresDisplay;
void Awake() {
instance = this;
highscoresDisplay = GetComponent<DisplayHighscores> ();
}
public static void AddNewHighscore(string username, int score, int levelLoaded)
{
instance.StartCoroutine (instance.UploadNewHighscore (username, score, levelLoaded));
}
IEnumerator UploadNewHighscore(string username, int score, int levelLoaded)
{
WWW WWW = new WWW (webURL + privateCode + "/add/" + WWW.EscapeURL (username) + "/" + score + "/" + levelLoaded);
yield return WWW;
if (string.IsNullOrEmpty (WWW.error)) {
print ("Upload Successful");
DownloadHighscores ();
}
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);
highscoresDisplay.OnHighscoresDownloaded(highscoresList);
}
else {
print ("Error uploading: " + 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]);*
-
int levelLoaded = int.Parse(entryInfo[2]);*
_ highscoresList = new Highscore(username,score, levelLoaded);_
print (highscoresList.username + ": " + highscoresList_.score + ": " + highscoresList*.levelLoaded);
}
}
}*_
public struct Highscore {
* public string username;*
* public int score;*
* public int levelLoaded;*
* public Highscore(string _username, int _score, int _levelLoaded) {*
* username = _username;
score = _score;
levelLoaded = _levelLoaded;*
* }*
}
_*