Arcade style top score system

So I am making a platformer with an arcade scoring system at the end, where it will have the 10 highest scores saved and you input a 3 digits to save your name on it. I want it to save in a text file and for to remain when the game is closed and booted up again. Thank you for the help.

I think for convenient, you should use either Defold Persist or DefSave.

1 Like

This was asked on Discord a while back: Discord

My answer now is the same as on Discord, so let’s break this down into manageable pieces:

  1. You save and load data using sys.save() and sys.load(). The data you save is a Lua table. You can see an example of this is practice in this example which saves and loads a single highscore:
  1. To keep track of the 10 highest scores+names you need to figure out a good structure of your highscore table. I suggest to structure it like this:
local highscores = {
   { score = 500, name = "AAA" },
   { score = 400, name = "BBB" }
}

This structure will let you use the table.sort() Lua function with a custom comparator function to compare the score value of each entry:

local highscores = {
    { score = 500, name = "AAA"},
    { score = 400, name = "BBB"},
    { score = 600, name = "CCC"}
}

-- sort scores using custom comparator
table.sort(highscores, function(a, b) return a.score > b.score end)

for _,entry in pairs(highscores) do
    print(entry.score, entry.name)
end
  1. Input three digits. There is an example of key input here:
1 Like

Thanks for the reply and information, I have managed to do something similar to this already but I am having trouble with applying my score and name when I input my name and apply to my list. Any advice on this?

Hard to say without looking at the full project. I see on Discord that you’re receiving help there.