Making Savegames

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
CanadianGamer
Party member
Posts: 132
Joined: Tue Jun 30, 2015 1:23 pm
Location: Canada
Contact:

Making Savegames

Post by CanadianGamer »

Can Anyone help me I'm trying to make a game that saves both the settings and the Highscores.
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
User avatar
Jack5500
Party member
Posts: 149
Joined: Wed Dec 07, 2011 8:38 pm
Location: Hamburg, Germany

Re: Making Savegames

Post by Jack5500 »

There are a few libraries that can help you with that:
https://github.com/JanWerder/awesome-lo ... ialization
Last edited by Jack5500 on Sun Oct 04, 2015 4:55 pm, edited 1 time in total.
User avatar
CanadianGamer
Party member
Posts: 132
Joined: Tue Jun 30, 2015 1:23 pm
Location: Canada
Contact:

Re: Making Savegames

Post by CanadianGamer »

Thank You
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
_Juice
Prole
Posts: 2
Joined: Sun Oct 04, 2015 2:32 pm

Re: Making Savegames

Post by _Juice »

The method I use is a library to turn tables into JSON files and save that. You can open the file and then turn the JSON into a table and use it.
"A man may die, a nation may rise and fall, but an idea lives on." - John F. Kennedy
User avatar
Alexar
Party member
Posts: 174
Joined: Thu Feb 05, 2015 1:57 am
Location: Chengdu,China

Re: Making Savegames

Post by Alexar »

i wrote an easy method, just copy the table you need into file as lua script. the output is string, you can print it to test.

Code: Select all

function table.save(tab,name)
    name=name or "test"
    local output="local "..name.."=\n"
    local function ergodic(target,time)
        time=time+1
        output=output.."{\n"
        for k,v in pairs(target) do
            output=output .. string.rep("\t",time)
            if type(v)=="table" then
                if type(k)=="number" then
                    output=output.."["..k.."]".."="
                elseif type(k)=="string" then
                    output=output.."[\""..k.."\"]="
                end 
                ergodic(v,time)
                output=output .. string.rep("\t",time)
                output=output.."},\n"
            elseif type(v)=="string" then
                if type(k)=="number" then
                    output=output.."["..k.."]".."=\""..v.."\",\n"
                elseif type(k)=="string" then
                    output=output.."[\""..k.."\"]=\""..v.."\",\n"
                end 
            elseif type(v)=="number" then
                if type(k)=="number" then
                    output=output.."["..k.."]".."="..v..",\n"
                elseif type(k)=="string" then
                    output=output.."[\""..k.."\"]="..v..",\n"
                end 
            end
        end
    end
    ergodic(tab,0)
    output=output.."}\n return "..name
    return output 
end
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Making Savegames

Post by Robin »

Alexar wrote:i wrote an easy method, just copy the table you need into file as lua script. the output is string, you can print it to test.
Note that that method doesn't deal with cycles or some other types of data: strings containing ", nan, inf, keys that aren't strings or numbers, values that aren't tables, strings or numbers (like booleans), ...

There are plenty of good serialisation libraries available, I recommend using one of those (especially binser or one of my libraries: Ser, Lady or Smallfolk).
Help us help you: attach a .love.
User avatar
Alexar
Party member
Posts: 174
Joined: Thu Feb 05, 2015 1:57 am
Location: Chengdu,China

Re: Making Savegames

Post by Alexar »

Robin wrote: Note that that method doesn't deal with cycles or some other types of data: strings containing ", nan, inf, keys that aren't strings or numbers, values that aren't tables, strings or numbers (like booleans), ...

There are plenty of good serialisation libraries available, I recommend using one of those (especially binser or one of my libraries: Ser, Lady or Smallfolk).
yeah, I forgot boolean. i still use binser or bintable in my own project. but this is an easy way to convert table to readable string.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 172 guests