Wowie Jam! Update #4 Elegantly Making a Godot Game Exit

A big nicety is to make the game quit when a player hits the ESC key. Especially when one’s Godot game is going full screen so there isn’t a close button provided by the OS. This turned out to be pretty easy. I added this to the globals.gd file (see the previous update on making globals).

func _process(delta):
#	# Called every frame. Delta is time since last frame.
#	# Update game logic here.
	if Input.is_action_pressed ("ui_cancel"):
		get_tree().quit()
	pass

From what I’ve read “ui_cancel” is the new fancy term for the ESC key in Godot 3. I’m guessing it used to be “key_exit” from this post.

“ui_cancel” seems to include the ESC key as well as various buttons on different style controllers. Whatever quits your boat.

Note that the official docs talk about notifying all the nodes about the program ending (I guess they all get a “the sky is falling!” message from Chicken Little). However, there’s nothing Uncontrollable Spaceship needs to save at this point so I think it safe to just get out of Dodge.

Sharing is caring 81766 style!