Question by
symingtonanimation · Apr 07, 2020 at 08:10 PM ·
databasescorejsonleaderboard
How do delete the lowest value on my list?
How do I delete the lowest on my leaderboard? I have tried to delete the last index, but it keeps deleting every odd number. Here is the code.
public void AddHighscoreEntry(int score, string name) {
// Create HighscoreEntry
HighscoreEntry highscoreEntry = new HighscoreEntry(score, name);
// Load saved Highscores
if (highscores == null)
{
// There's no stored table, initialize
highscores = new Highscores()
{
highscoreEntryList = new List<HighscoreEntry>()
};
}
else if (highscores.highscoreEntryList.Count >= 5)
{
//highscores.highscoreEntryList = new List<HighscoreEntry>(5);
for (int i = 0; i < highscores.highscoreEntryList.Count; i++)
{
long minScore = long.MaxValue;
var count = highscores.highscoreEntryList.Count;
int Hscore = highscores.highscoreEntryList[count - 1].score;
Debug.Log("Hscore: " + Hscore);
int[] highList = { Hscore };
var vencedor = Mathf.Min(highList);
Debug.Log("vencedor: " + vencedor);
foreach (var child in highscores.highscoreEntryList)
{
var childScore = highscores.highscoreEntryList[i].score;
if (vencedor < minScore)
{
minScore = vencedor;
Debug.Log("MinScore: "+ minScore);
}
}
highscores.highscoreEntryList.RemoveAt(Hscore);
//Debug.Log("Find: " + Hscore + " Name: " + Hname + " count: " + count);
}
}
highscores.highscoreEntryList.Add(highscoreEntry);
// Save updated Highscores
string json = JsonUtility.ToJson(highscores);
Debug.Log("Saved: " + json);
mDatabase.Child("highscoreEntry").SetRawJsonValueAsync(json);
}
screenshot-2020-04-07-at-215436.png
(359.4 kB)
Comment
Your answer
Follow this Question
Related Questions
Whats the best option for an item database for a single player game 2 Answers
What should I use, a Dictionary with 100 entries or a class with 100 variables? 0 Answers
How to load different content from database when select different option? 0 Answers