0 votes

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..

in Engine by (42 points)

1 Answer

+1 vote

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)

by (1,963 points)
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.