How do i get my chat box to become visible with area2d?

I am making a platformer with a dialogue system and the actual chat box is working but I can not get it to pop up when the player enter the collision zone of the area 2d of the npc.


note: the player does have a player method

Make sure to paste code instead of screenshots. Does your print “working”?

Thank you for the information this is my first time doing this.

No, “working” does not print.

NPC Script:

extends CharacterBody2D

var player_in_chat_zone = false

func _on_area_2d_body_entered(body: Node2D) -> void:
	if body.has_method("player"):
		print("working")
		player_in_chat_zone = true
		$Dialogue.start()


func _on_dialogue_dialogue_finished():
	player_in_chat_zone = false

Dialogue Script:

extends Control

signal dialogue_finished

@export_file("*.json") var d_file

var dialogue = [] #array holding all dia
var current_dialogue_id = 0 #index of dia
var d_active = false #checks if dia is active

func _ready() -> void: #at the start call the start func
	$NinePatchRect.visible = false
	print("not vis")
	
func start(): #starts dia 
	print("start")
	if d_active:
		return
	d_active = true
	$NinePatchRect.visible = true
	dialogue = load_dialogue()
	current_dialogue_id = -1
	next_script() #calls next script func
	
func load_dialogue():
	var file = FileAccess.open("res://dialogue/alex_dialogue1.0.json", FileAccess.READ)
	var content = JSON.parse_string(file.get_as_text())
	return content 

func _input(event: InputEvent) -> void:
	if !d_active:
		return
	if event.is_action_pressed("enter"): #if e is pressed goes to next line
		next_script()

func next_script():
	current_dialogue_id += 1 # goes to next line
	if current_dialogue_id >= len(dialogue): #makes sure index does not exceed amount of dia
		d_active = false #dia is no longer active
		$NinePatchRect.visible = false #textbox disapears
		emit_signal("dialogue_finished")
		return
		
	$NinePatchRect/Name.text = dialogue[current_dialogue_id]['name']
	$NinePatchRect/Text.text = dialogue[current_dialogue_id]['text']

then it must be that the player body does not have a method “player” or the collision layers/monitoring are not set correctly.

The player body does have a player function and i have set monitoring to true but it still does not work.

It may be the collision layer but I am not sure what they should be. How would i go about setting them correctly?

The collision layer of the player must be present in the area’s mask. If the player has layer 2 then the area must include mask 2

Holy smokes. Thank you so much brother :slight_smile: