How to check if body is in group ? The identifier 'body' isnt declared in the current scope

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By quadra123
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”?

:bust_in_silhouette: Reply From: ponponyaya

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.