Scoreboard question

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Periwasmarkedasspam
Prole
Posts: 9
Joined: Sun Feb 08, 2015 5:30 am

Scoreboard question

Post 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?
User avatar
ivan
Party member
Posts: 1918
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Scoreboard question

Post 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.
User avatar
Periwasmarkedasspam
Prole
Posts: 9
Joined: Sun Feb 08, 2015 5:30 am

Re: Scoreboard question

Post by Periwasmarkedasspam »

I dont know how this work... Can someone show me how it works?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Scoreboard question

Post 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 
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], darkfrei and 3 guests