Doing stuff on exit
Posted: Thu Feb 11, 2010 2:57 pm
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:
Here's the code, one line in the love.run is changed, at the event iterator:
Code: Select all
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