Okay, I did a quick test for everyone who wants to save stuff on exit. It calls a function (love.quit) when the game shuts down, where the user can call their save function. To improve this I will create a function for saving variables easily using a technology I found in the Android syntax. It creates a bundle with all values using keys, for example bundle.putNumber("A number value", 42). And for reading, bundle.getNumber("A number value"). I might make it auto detect the type, this was just an example. The script will be used together with this to make it easier for other developers to save game states.
Here's the code, one line in the love.run is changed, at the event iterator:
function love.quit()
end
function love.run()
if love.load then love.load(arg) end
local dt = 0
-- Main loop time.
while true do
if love.timer then
love.timer.step()
dt = love.timer.getDelta()
end
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics then
love.graphics.clear()
if love.draw then love.draw() end
end
-- Process events.
if love.event then
for e,a,b,c in love.event.poll() do
if e == "q" then
if love.audio then
love.audio.stop()
end
love.quit() --Changed line!!
return
end
love.handlers[e](a,b,c)
end
end
if love.timer then love.timer.sleep(1) end
if love.graphics then love.graphics.present() end
end
end
1. Yes, I just used is a reference.
2. That saves it to a table, but I was thinking to add something to save the values to a file after. When the game is started again the values can be restored using the values from the read file
kalle2990 wrote:2. That saves it to a table, but I was thinking to add something to save the values to a file after. When the game is started again the values can be restored using the values from the read file
I know how to use metatables, they have different stuff for doing things with them. I've been using them on my GUI which I stopped working on atm, it would need some code optimizations...