Page 1 of 1

Detecting/interrupting when a user is quitting the program

Posted: Sun Jul 30, 2017 11:29 am
by HellzoneByron
I'm working on a multiplayer game, and I'm currently looking into a way to prepare the client for a shutdown with Alt-F4 or ⌘Q if a user tries to midgame. As it stands, both sides work, however if a player quits, it currently leaves the player on the server for a few brief moments.

I've tried the usual keypress routines but they don't seem to beat the quit command (at least on macOS). How do I get LÖVE to run custom commands or a function as soon as LÖVE is closed?

Re: Detecting/interrupting when a user is quitting the program

Posted: Sun Jul 30, 2017 1:48 pm
by slime
You can use the love.quit callback which is called when the user quits the game via command-Q etc. It also has the ability to prevent the game from quitting, so you can use it to wait for the client to successfully send a disconnect event to the server, for example (and then use love.event.quit to quit for real once that's complete).

Re: Detecting/interrupting when a user is quitting the program

Posted: Mon Jul 31, 2017 7:55 pm
by HellzoneByron
Excellent, thank you. :-)

I'm now worried to see what else I missed on the love function callbacks page!