First, you'll need to create a variable called i and a list called highscores. Once you've done this, use this script for a highscore list:
set [i v] to (1) repeat until <(i) = [h]>//* if <not <(item (i) of [highscores v]) > (score)>> insert (score) at (i) of [highscores v] set [i v] to [h] else change [i v] by (1) if<(i) > (length of [h v])> insert (score) at [last v] of [highscores v] set [i v] to [h] end end end* - This repeat loop and the scripts in it check to see where to put the score.
Last edited by ErnieParke (2012-11-03 12:44:19)
Offline
new to scratch , I'm assuming a list is a one dimensional array with h pointing to last cell
if i = h - 1 and new score < highscores[h-1] then first if is false goto second if
now i = h so we don't do second if but get out of the loop because i = h; this means we never put the lowest score in cell h!!!!
also say new score = highscores[i] then 1st if is true so we over write old score, but both scores are the same, inefficient code.
looks like the problem is the "not" of first if, a true on the first if is both of these cases, when highscores[i] < score, but also when highscores[i] is = score
would it be better to just say for first if: if highscores[i] < score?
do this then it looks like highest score will be in the last cell
Paul USA
Offline
ErnieParke is right, but that's for a personal high score list. Unfortunately, in this version of scratch, you can't save data for all players.
Offline