Making Savegames
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- CanadianGamer
- Party member
- Posts: 132
- Joined: Tue Jun 30, 2015 1:23 pm
- Location: Canada
- Contact:
Making Savegames
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
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
Re: Making Savegames
There are a few libraries that can help you with that:
https://github.com/JanWerder/awesome-lo ... ialization
https://github.com/JanWerder/awesome-lo ... ialization
Last edited by Jack5500 on Sun Oct 04, 2015 4:55 pm, edited 1 time in total.
- CanadianGamer
- Party member
- Posts: 132
- Joined: Tue Jun 30, 2015 1:23 pm
- Location: Canada
- Contact:
Re: Making Savegames
Thank You
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
Re: Making Savegames
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
Re: Making Savegames
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
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Making Savegames
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), ...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.
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.
Re: Making Savegames
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.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).
Who is online
Users browsing this forum: Google [Bot] and 7 guests