error CS0201?
I'm making a highscore box in the main menu. In the script I have, i've gotten it down to one error on this line:
hscorecount == PlayerPrefs.GetInt(highScoreKey, 0);
The error: CS0201: 'Only assignment, call, increment, decrement, and new object expressions can be used as a statement'.
All the code:
void Start()
{
//Get the highScore from player prefs if it is there, 0 otherwise.
hscorecount == PlayerPrefs.GetInt(highScoreKey, 0);
}
void Update()
{
GetComponent<GUIText>().text = "Score: " + score.ToString();
}
void OnDisable(){
//If our scoree is greter than highscore, set new higscore and save.
//for (i = 0; i<hscorecount.Length; i++){
//Get the highScore from 1 - 5
// highScoreKey = "HighScore"+(i+1).ToString();
//hscorecount = PlayerPrefs.GetInt(highScoreKey,0);
//if score is greater, store previous highScore
//Set new highScore
//set score to previous highScore, and try again
//Once score is greater, it will always be for the
//remaining list, so the top 5 will always be updated
if(score > hscorecount){
int temp = hscorecount;
PlayerPrefs.SetInt(highScoreKey,score);
score = temp;
}
}
}
Answer by Rob2309 · Apr 13, 2016 at 05:59 PM
A double equal sign compares the two values, which is invalid in that context, what you want to do is only use a single one, which assigns the value to the specified variable... In the code you posted, however, this error is already fixed so i guess you have already found the solution :D
If I make it just one equals sign, the error: Cannot implicitly convert type 'int' to 'int[]' ..?
I'm new to c# so i'm not completely sure what an array is, I have 'hscorecount' as a static float in a 'HUD script', the 'HUD script' saves the highest score to player prefs and displays it on the screen while playing, but what i'm trying to do is display the top five scores on the main menu.