Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function AddRecord(args:Array)
- {
- var playerName:String = args[0]; // retrieve player name from first array element
- var playerScore:int = args[1]; // retrieve player score from second array element
- var added:boolean = false;
- // if there are already high scores
- if (noHighScores > 0)
- {
- // loop over the scores to correctly position new players score
- for (var i = 0; i < noHighScores; i++)
- {
- /////The next line is the errornous one
- // if new score is greater than the current high score
- if (playerScore > parseInt(playerScoresList[i]))
- {
- // enter the new high score
- playerScoresList.splice(i, 0, playerScore);
- // if there are more scores than the maximum allowed, remove the last entry
- if (playerScoresList.length > highScoresLimit) playerScoresList.pop();
- // repeat for the name
- playerNamesList.splice(i, 0, playerName);
- if (playerNamesList.length > highScoresLimit) playerNamesList.pop();
- added = true;
- // break out of the loop
- break;
- }
- }
- // if score is less than all current scores, but there are less scores than the limit, add the score
- if (noHighScores < highScoresLimit && !added)
- {
- playerScoresList.push(playerScore);
- playerNamesList.push(playerName);
- }
- }
- else // if no scores, simply add new score to the list
- {
- playerScoresList[0] = playerScore;
- playerNamesList[0] = playerName;
- }
- // update noHighScores
- noHighScores = playerNamesList.length;
- // return lists as CSV
- var playerScoreString:String = playerScoresList.ToString();
- var playerNameString:String = playerNamesList.ToString();
- // update player prefs
- PlayerPrefs.SetString("playerNamesList", playerNameString);
- PlayerPrefs.SetString("playerScoresList", playerScoreString);
- }
Add Comment
Please, Sign In to add comment