How to quit the game [SOLVED]

I want to quit my game when I press the Escape key. How would I do that?

I attached this code to a game object and it’s working.

function init(self)
	msg.post(".", "acquire_input_focus")
end

function on_input(self, action_id, action)
	if action_id == hash("escape") then
		msg.post("@system:", "exit", {code = 0})
	end
end
1 Like

If this is purely for convenience when testing out the project (and being able to quickly close the screen when doing testing) then you can go to File -> Preferences and check the box “Escape Quits Game” in the editor.

6 Likes