0 votes
var items_in_range = {} 

var inarea= false
func _ready():
pass
func _on_Area2D_body_entered(body):
items_in_range[body]= body 
print("entered")
inarea=true

func _input(event):
if event.is_action_pressed("TALKTONPC"):
    if inarea == true:
        if body.is_in_group("NPCHH"): #ERROR OCCURS HERE!!!
            var new_dialog = Dialogic.start("fionasays")
            add_child(new_dialog)


func _on_Area2D_body_exited(body):
if items_in_range.has(body):
    items_in_range.erase(body)
    print("exited")

The identifier 'body' isnt declared in the current scope. How can i check if the body enter the area is in group "NPCHH"?

in Engine by (35 points)

1 Answer

+1 vote
Best answer

I notoced that you use an dictionary to record those bodies, it looks like you may have more than one body, so you can use for loop to check all of them.

for body in items_in_range.values():
    if body.is_in_group("NPCHH"):
        print("blablabla")
        # do what you want to do.
by (526 points)
selected by
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.