How do I create a save game feature in love2d?

2020-07-22 18:22发布

问题:

I am new to game development but I need to know if it is possible to create a save game feature in love2d with lua.

回答1:

Sure. You can use a variety of libraries available. My current recommendation is Ser Binser (Ser has been deprecated). This process is called "table serialization." Then, you can do something like this to effectively create a "save."

local ser = require 'Path.to.ser'
local save 

function love.load()
    if love.filesystem.exists( 'Save.lua' ) then
        save = love.filesystem.load( 'Save.lua' )
    else
        save = {} -- Put settings in here.
    end
end
-- etc. etc.
function love.quit()
   love.filesystem.write( 'Save.lua', save )
end


标签: lua love2d