Page 1 of 1

Scoreboard question

Posted: Thu May 14, 2015 7:16 am
by Periwasmarkedasspam
Hello, im trying to add a scoreboard, but i dont know how to store values on a table permanently. How can i do this?

Re: Scoreboard question

Posted: Thu May 14, 2015 8:43 am
by ivan
Take a look at Robin's "ser" library which can serialize the table to a string.
Then you save that string to a file and "require" it next time you run the game.

Re: Scoreboard question

Posted: Thu May 14, 2015 4:39 pm
by Periwasmarkedasspam
I dont know how this work... Can someone show me how it works?

Re: Scoreboard question

Posted: Fri May 15, 2015 12:31 am
by Robin
In this case, you'd probably want to download Ser and do something like:

Code: Select all

local serialize = require 'ser'

function love.load()
    local ok, chunk = pcall(love.filesystem.load, 'highscores.lua')
    if ok then
        highscores = chunk()
    else
        highscores = {}
    end
end

function love.quit()
    love.filesystem.write('highscores.lua', serialize(highscores))
end