The following works great to save and print out the data
sav = playdate.datastore.read("high-scores")
if save == nil then
sav = {}
end
table.insert(sav, { time = timeElapsed, player = "ABC" })
playdate.datastore.write(sav, "high-scores")
printTable(sav)
however I want to display the fastest (lowest) time when you play the game next time.
So I need to read the file and check if the current score is less than (aka faster) write that to the data store
in both cases faster or not I want to display the highscore for the timeElaspsed ? (not worrying about player names at the moment)
I am thinking at the moment this rough hack
sav = playdate.datastore.read("high-scores")
if sav == nil then
sav = {}
end
if timeElapsed <= table.sav[1{time ??}]] then
table.remove(sav, 1)
table.insert(sav, 1 , { time = timeElapsed, player = "adam", level = "test" })
end
I think I have done it !
local highscores = playdate.datastore.read("high-scores")
if highscores == nil then
highscores = {
{
time = 11111,
player = "adam",
},
{
time = 22222,
player = "adam",
},
{
time = 33333,
player = "adam",
}
}
-- print(highscores[LEVEL_PLAYED].time)
end
if timeElapsed < highscores[LEVEL_PLAYED].time then
table.remove(highscores, LEVEL_PLAYED)
table.insert(highscores, LEVEL_PLAYED, { time = timeElapsed, player = "adam" })
-- printTable(highscores)
end
playdate.datastore.write(highscores, "high-scores")