Hi I'm trying to make my game quit nicely both on 0.7.2 and 0.8.0. Since the commands are different, love.event.push('q') and love.event.push('quit'), I tried using pcall like this
if pcall(function() love.event.push('q') end) then
else
love.event.push('quit')
end
However, when I run this on 0.8.0, the blue screen still appears and says "Unknown event 'q'". It is as if LÖVE error aren't caught by pcall properly. Is this perhaps a bug in 0.8.0 or am I doing something wrong?
I guess a workaround could be something like checking at runtime what version it is currently running on.
Good to know. I don't use 0.8.x myself, so I have no way to test that. But the code above works on 0.7.x, and I got confirmation that it also works in 0.8.x.
function quit()
local f = love.event.quit or love.event.push
f('q')
end
...
if key == 'escape' then quit() end
Notice that love.event.quit doesn't take any parameters. But it will not complain if you shove it a 'q'.
That works regardless of wether 0.8 has love.event.push (which it does), your code simply test wether or not "love.event.quit" exists, and uses that if possible. That's a smart solution.
I think love.event.quit is actually slightly different from love.event.push("quit"/"q"). The former will quit LÖVE right away, while the latter will wait until the next time events are polled, which could be nearly an entire frame. Usually it won't matter though.