Highscores Engine

Here is a basic engine to save the top 10 scores. It saves and reads LocalData. I put this together quite quickly so let me know if there’s any bugs or anything.

To add a score to the list simply call: save_score(score)

Note: “score” is whichever variable you are adding to the list.

function print_scores() --Prints out the top 10 scores. Likely this is not how you will want to display the text on the screen... you'll probably want to use the text function to draw it on the screen. print(readLocalData("1",0)) --Prints the score, if no score is found it defaults to 0 (that's what the second parameter is used for print(readLocalData("2",0)) print(readLocalData("3",0)) print(readLocalData("4",0)) print(readLocalData("5",0)) print(readLocalData("6",0)) print(readLocalData("7",0)) print(readLocalData("8",0)) print(readLocalData("9",0)) print(readLocalData("10",0)) end function save_score(p) temp={} --orginal score list temp2={} --updated score list table.insert(temp,readLocalData("1",0)) table.insert(temp,readLocalData("2",0)) table.insert(temp,readLocalData("3",0)) table.insert(temp,readLocalData("4",0)) table.insert(temp,readLocalData("5",0)) table.insert(temp,readLocalData("6",0)) table.insert(temp,readLocalData("7",0)) table.insert(temp,readLocalData("8",0)) table.insert(temp,readLocalData("9",0)) table.insert(temp,readLocalData("10",0)) found=false for i=1,10 do if p>=temp[i] and found==false then found=true table.insert(temp2,p) for j=i+1,10 do table.insert(temp2,temp[j-1]) end else table.insert(temp2,temp[i]) end end saveLocalData("1",temp2[1]) saveLocalData("2",temp2[2]) saveLocalData("3",temp2[3]) saveLocalData("4",temp2[4]) saveLocalData("5",temp2[5]) saveLocalData("6",temp2[6]) saveLocalData("7",temp2[7]) saveLocalData("8",temp2[8]) saveLocalData("9",temp2[9]) saveLocalData("10",temp2[10]) end