-2

So I'm trying to pull playername and count from a file, and save them into a variable for high scores..

I dont understand why this error is happening though. At all. I've also tried to ask on the unity forums but this hasn't helped much.

Code:

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
using System;

public class highscores : MonoBehaviour {

 public int[] HighScoreList;
 public string[] HighScoreListNames;
 public int score;
 public Text HighScore0;
 public Text HighScore1;
 public Text HighScore2;
 public Text HighScore3;
 public Text HighScore4;

 void Awake()
 {
     HighScoreList = new int [5];
     HighScoreList [0] = 0;
     HighScoreList [1] = 0;
     HighScoreList [2] = 0;
     HighScoreList [3] = 0;
     HighScoreList [4] = 0;
     HighScoreListNames = new string [5];
     HighScoreListNames [0] = "";
     HighScoreListNames [1] = "";
     HighScoreListNames [2] = "";
     HighScoreListNames [3] = "";
     HighScoreListNames [4] = "";
 }

 void GetScore () 
 {
     string[] currentscore = System.IO.File.ReadAllLines (@"C:\Users\Plum\Desktop\Pixel Ninjav3.3\Assets\leaderboard.txt");
     score = Convert.ToInt32(currentscore[1]);
     if (score >= HighScoreList[0])
     {
         HighscoreList[4] = HighScoreList[3];
         HighscoreList[3] = HighScoreList[2];
         HighscoreList[2] = HighScoreList[1];
         HighscoreList[1] = HighScoreList[0];
         HighscoreList[0] = score;
         HighScoreListNames[4] = HighScoreListNames[3];
         HighScoreListNames[3] = HighScoreListNames[2];
         HighScoreListNames[2] = HighScoreListNames[1];
         HighScoreListNames[1] = HighScoreListNames[0];
         HighScoreListNames[0] = currentscore[0];
     }
     else if (score >= HighScoreList[1])
     {
         HighscoreList[4] = HighScoreList[3];
         HighscoreList[3] = HighScoreList[2];
         HighscoreList[2] = HighScoreList[1];
         HighscoreList[1] = score;
         HighScoreListNames[4] = HighScoreListNames[3];
         HighScoreListNames[3] = HighScoreListNames[2];
         HighScoreListNames[2] = HighScoreListNames[1];
         HighScoreListNames[1] = currentscore[0];
     }
     else if (score >= HighScoreList[2])
     {
         HighscoreList[4] = HighScoreList[3];
         HighscoreList[3] = HighScoreList[2];
         HighscoreList[2] = score;
         HighScoreListNames[4] = HighScoreListNames[3];
         HighScoreListNames[3] = HighScoreListNames[2];
         HighScoreListNames[2] = currentscore[0];
     }
     else if (score >= HighScoreList[3])
     {
         HighscoreList[4] = HighScoreList[3];
         HighscoreList[3] = score;
         HighScoreListNames[4] = HighScoreListNames[3];
         HighScoreListNames[3] = currentscore[0];
     }
     else if (score >= HighScoreList[4])
     {
         HighscoreList[4] = score;
         HighScoreListNames [4] = currentscore[0];
     }

 }
}
MethodMan
  • 18,625
  • 6
  • 34
  • 52
Plumel
  • 45
  • 9
  • @DanielLawton, have you used the debugger to determine which line it's failing on exactly.. ? – MethodMan Mar 20 '16 at 20:19
  • @GrantWinney All the lines beneath the ifs and else ifs to do with the HighScoreList array – Plumel Mar 20 '16 at 20:32
  • @MethodMan It's failing on all lines with HighScoreList[4] = HighScoreList [3] etc under the if and else if statements – Plumel Mar 20 '16 at 20:34

1 Answers1

1

C# is case sensitive. Meaning you cant mix "HighScoreList" and "HighscoreList".

You only declared HighScoreList. With Score capitalized. But in your ifs you also use HighscoreList with score in lower case.

Mario Dekena
  • 843
  • 6
  • 20