For example this works (note: there's 2 different types of serialization there I was testing):
Code: Select all
player = {
x = 300,
y = 300,
width = 64,
height = 64,
speed = 100,
}
function love.keypressed( key, unicode)
if key == "q" then
love.filesystem.write("player.sav", table.serialize(player,true,true))
elseif key == "e" then
player = loadstring(love.filesystem.read("player.sav"))()
end
if key == "z" then
local file
file = love.filesystem.newFile( "config.txt" )
file:open("w")
file:write( TSerial.pack( player ) )
file:close()
elseif key == "c" then
local file
love.filesystem.setIdentity( "mygame" )
if love.filesystem.exists( "config.txt" ) then
file = love.filesystem.newFile( "config.txt" )
file:open("r")
player = TSerial.unpack( file:read() )
file:close()
end
end
end
But I need to work out something that would be more like:
Code: Select all
player = {
x = 300,
y = 300,
width = 64,
height = 64,
speed = 100,
}
player2 = {
x = 300,
y = 300,
width = 64,
height = 64,
speed = 100,
}
players = { }
table.insert (players, player1)
table.insert (players, player2)
.... save players table through serialization methods instead of creating a sav file for player one AND player 2 which would obviously work but... ....
I'm missing a piece of the puzzle here, and perhaps someone could explain it better, please?