Trigger a Text Box when entering a certain area and pressing a button.

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

Hey, i’m currently working on a small pice of code. It should handle the case, whenever the player is in a certan area and presses a certain button the dialouge box should appear and when he leves the area the box should disappear.

This is my code:

extends Polygon2D

var inarea = false

func _ready():

func _on_Area2D_body_entered(body):
	var inarea = true
func _physics_process(delta):
	if (Input.is_action_just_pressed("attack")):
		if inarea == true:

func _on_RichTextLabel_done():

func _on_Area2D_body_exited(body):
	if inarea == true:
		inarea = false

my script worked until i added the check for the button press. I have no clue why is broken now…

:bust_in_silhouette: Reply From: deaton64

I think it’s because inarea never gets set to false.

You enter, inarea is set to true.
You leave, inarea is true so you play the animation, the else never happens.

Drop the else? (maybe)