love.event.restart

Available since LÖVE 12.0
This function is not supported in earlier versions.

Restarts the game without relaunching the executable, by adding a quit event with a "restart" parameter to the queue. This cleanly shuts down the main Lua state instance and creates a brand new one.


Equivalent to love.event.push("quit", "restart", restartarg).


O.png If LÖVE is programmatically restarted, all active Lua threads must stop their work and the main thread must wait for them to finish, otherwise LOVE may fail to start again.  


Function

Synopsis

love.event.restart( restartarg )

Arguments

Variant restartarg (nil)
A value which will appear in the love.restart table field after restarting. Can be a table containing multiple Lua values.

Returns

Nothing.

Example

local restartcount = tonumber(love.restart) or 0

function love.keypressed(k)
   if k == "r" then
      love.event.restart(restartcount + 1)
   end
end

function love.draw()
   love.graphics.print("Restarted " .. restartcount .. " times.", 8, 8)
end

See Also

Other Languages