0 votes

Total newb here, I have a question about something I'm getting stuck on with a new 2D project. I added a sprite background and it shows no problem when I run the test. I setup the esc key as "key_exit" in the Input Map. Then I created a node2D as the root and added the following script to it:

extends Node2D

func _ready():
   if Input.is_action_pressed("key_exit"):

It doesn't work. I'm trying to create a simple loop that listens for esc key presses and quits when I press the escape key. If I add get_tree().quit() without the if condition, it quits as soon as it starts. How do I get it to "listen" for my if condition? What am I doing wrong here?

asked Apr 19, 2017 in Engine by Oliver_M (25 points)
recategorized Apr 19, 2017 by Oliver_M

1 Answer

+3 votes
Best answer

I figured it out. I was able to get it working with:

extends Node2D

func _ready():

func _process(delta):
   if Input.is_action_pressed("key_exit"):
answered Apr 20, 2017 by Oliver_M (25 points)

One of the RARE questions I CAN answer and you beat me to it :-)

Checking for input event (set_process_input(true) in godot 2) should work too, just changes to event.is_action_pressed inside _input.

Gamefromscrtatch tutorials and official docs have examples of the ways to handle user inputs.

The ESC key is mapped to ui_cancel in godot 3.
Look in Project Settings on the Input Map tab

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.