Guest User

Untitled

a guest
Nov 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. function AddRecord(args:Array)
  2. {
  3. var playerName:String = args[0]; // retrieve player name from first array element
  4. var playerScore:int = args[1]; // retrieve player score from second array element
  5. var added:boolean = false;
  6.  
  7. // if there are already high scores
  8. if (noHighScores > 0)
  9. {
  10. // loop over the scores to correctly position new players score
  11. for (var i = 0; i < noHighScores; i++)
  12. {
  13.  
  14.  
  15.  
  16. /////The next line is the errornous one
  17.  
  18.  
  19.  
  20. // if new score is greater than the current high score
  21. if (playerScore > parseInt(playerScoresList[i]))
  22. {
  23. // enter the new high score
  24. playerScoresList.splice(i, 0, playerScore);
  25.  
  26. // if there are more scores than the maximum allowed, remove the last entry
  27. if (playerScoresList.length > highScoresLimit) playerScoresList.pop();
  28.  
  29. // repeat for the name
  30. playerNamesList.splice(i, 0, playerName);
  31. if (playerNamesList.length > highScoresLimit) playerNamesList.pop();
  32.  
  33. added = true;
  34.  
  35. // break out of the loop
  36. break;
  37. }
  38. }
  39.  
  40. // if score is less than all current scores, but there are less scores than the limit, add the score
  41. if (noHighScores < highScoresLimit && !added)
  42. {
  43. playerScoresList.push(playerScore);
  44. playerNamesList.push(playerName);
  45. }
  46. }
  47. else // if no scores, simply add new score to the list
  48. {
  49. playerScoresList[0] = playerScore;
  50. playerNamesList[0] = playerName;
  51. }
  52.  
  53. // update noHighScores
  54. noHighScores = playerNamesList.length;
  55.  
  56. // return lists as CSV
  57. var playerScoreString:String = playerScoresList.ToString();
  58. var playerNameString:String = playerNamesList.ToString();
  59.  
  60. // update player prefs
  61. PlayerPrefs.SetString("playerNamesList", playerNameString);
  62. PlayerPrefs.SetString("playerScoresList", playerScoreString);
  63. }
Add Comment
Please, Sign In to add comment