Detecting/interrupting when a user is quitting the program

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
HellzoneByron
Prole
Posts: 5
Joined: Sat Jul 01, 2017 5:58 pm
Contact:

Detecting/interrupting when a user is quitting the program

Post 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?

Code: Select all

room = {"Saskatoon","Poulsbo","Benettsville","Palmyra"}
Chicago = not Chicago
User avatar
slime
Solid Snayke
Posts: 3160
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

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

Post 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).
HellzoneByron
Prole
Posts: 5
Joined: Sat Jul 01, 2017 5:58 pm
Contact:

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

Post by HellzoneByron »

Excellent, thank you. :-)

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

Code: Select all

room = {"Saskatoon","Poulsbo","Benettsville","Palmyra"}
Chicago = not Chicago
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests