Difference between revisions of "love.quit"

m
m (Example)
(4 intermediate revisions by 2 users not shown)
Line 11: Line 11:
 
{{param|boolean|r|Abort quitting. If true, do not close the game.}}
 
{{param|boolean|r|Abort quitting. If true, do not close the game.}}
 
== Example ==
 
== Example ==
 +
This example shows how the return value of [[love.quit]] can be used to stop the closing of the game.
 
<source lang="lua">
 
<source lang="lua">
 +
local quit = true
 
function love.quit()
 
function love.quit()
  --This will be printed to the console on quit
+
    if quit then
  print("Thanks for playing. Please play again soon!")
+
        print("We are not ready to quit yet!")
 +
        quit = not quit
 +
    else
 +
        print("Thanks for playing. Please play again soon!")
 +
        return quit
 +
    end
 +
    return true
 
end
 
end
 
</source>
 
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::love]]
 
* [[parent::love]]
 +
* [[love.event.quit]]
 
[[Category:Callbacks]]
 
[[Category:Callbacks]]
 
{{#set:Description=Callback function triggered when the game is closed.}}
 
{{#set:Description=Callback function triggered when the game is closed.}}

Revision as of 20:44, 30 December 2015

Available since LÖVE 0.7.0
This callback is not supported in earlier versions.

Callback function triggered when the game is closed.

Function

Synopsis

r = love.quit( )

Arguments

None.

Returns

boolean r
Abort quitting. If true, do not close the game.

Example

This example shows how the return value of love.quit can be used to stop the closing of the game.

local quit = true
function love.quit()
    if quit then
        print("We are not ready to quit yet!")
        quit = not quit
    else
        print("Thanks for playing. Please play again soon!")
        return quit
    end
    return true
end

See Also


Other Languages