save game with tserial?

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
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

save game with tserial?

Post by pielago »

i tried a few ways to save my tables but when it comes to do it....
it fails i don't know why?
now tserial is it a good way to save tables? is that the right way or is there a super easier way??
can anyone point to me which direction to take if there is a better way and easy???
i am trying to make like a zelda game so ill need to save a lot of tables...

p.s how does Tserial work? i don't get wiki any examples?
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: save game with tserial?

Post by micha »

Saving and loading has two possible difficulties.
1) The technical one. You need to write some code that writes something to the hard drive and reads it later. There are two approaches for that. Either, save the data in Lua-language. Then writing it will be a bit difficult, but reading it is very simple, just a matter of one line. Or you save the data in a format that you make up yourself. That would probably a text-file, with your data included. In the first case, serialization is the way, to go. I do not have any experience with tserial, but that potentially does the trick.

2) The information management. Conceptually you have to think about, what data needs to be stored to fully recover the game state. Is it enough to only store one number (the level) or do you need to store all the character values, positions of enemies, etc..
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: save game with tserial?

Post by Robin »

pielago wrote:now tserial is it a good way to save tables? is that the right way or is there a super easier way??
Tserial has a number of problems (I've gone into detail on this elsewhere on the forums) which is why I don't recommend it. Instead, you could use something like Ser. If you download it, and put ser.lua next to your main.lua, you can put this at the top of your main.lua (or where-ever you want to put your saving code):

Code: Select all

local serialize = require 'ser'
and where you save, put something like:

Code: Select all

love.filesystem.write('nameofsavegame', serialize(gamedata))
where gamedata is the name of the table you have all the data that needs to be saved. The loading code would then be:

Code: Select all

gamedata = love.filesystem.load('nameofsavegame')()
Since you have a lot of tables, I suggest you do something like:

Code: Select all

love.filesystem.write('nameofsavegame', serialize({player, someothertable}))
and

Code: Select all

player, someothertable = unpack(love.filesystem.load('nameofsavegame')())
Help us help you: attach a .love.
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: save game with tserial?

Post by pielago »

that's one of the tables to save from many so...

Code: Select all

player={}
player.x=100
player.y=200
player.w=50
player.h=50
player.speed=300
player.life=5
like this???

Code: Select all

love.filesystem.write('scores', serialize(player))
--and to load like this?

Code: Select all

player = love.filesystem.load('score','player')()
or am i super confuse?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests