Showing a dialogue box when an Area2D has been entered and a specific button is pressed

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CatRass

I want a dialogue box to pop up when I enter the specific area, and press the accept key (z in my case) but when I use my code, the dialogue doesn’t work. The dialogue pops up when I make my code have it pop up when I just enter the area, but not with the if statement. What am I doing wrong?

   func _on_ComputerDetector_area_entered(area):
	if Input.get_action_strength("ui_accept"):
		$Speech.show()

Please use the Code-Sample formatting for your code (The { } above the text editor)
This makes your posts much more readable, and wont remove the underscores

whiteshampoo | 2020-06-25 08:27

:bust_in_silhouette: Reply From: Ertain

I think the code should be Input.is_action_pressed("ui_accept"), provided that the “z” key is bound to the “ui_accept” action, and that you account for when the player has entered the Area2D.

:bust_in_silhouette: Reply From: whiteshampoo
[...]_on_area_entered(area):

just executes the frame you really ENTER the area. It does not check if you are inside.
You can set a variable to true if you enter, and back to false when you exit. Then check this variable, because it can tell you if you are inside or not. (faster)

You can also use get_overlapping_areas() (or bodies) (slower)