Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | RakuNana |
Hello everyone! Hope all is going well for everyone Anyways, I’m currently trying to implement a simple dialogue system. Where when the player walks up to an NPC and presses the talk button, a dialogue box pops up, shows it’s message, and then disappears. Pretty standard stuff. My problem is that when I try to instance the dialogue box using the signals "_on_Area2D_area_entered(_area: Area2D), and _on_Area2D_area_exited(_area: Area2D) the dialogue box will still appear even after I have exited the Area2d. An example of what I mean is, I’ll walk up to the NPC till I am in the area box(I have it print true, so I know I have activated the signal and false when I have left) then I’ll walk to the other side of the map and press the talk button and the dialog box pops up. What I would like to know is how I can have the dialogue box appear only when I’m inside the NPC’s Area2d and press the talk button. For whatever reason it can still be called after I have left the Area2d. Thanks in advance! I’ll add my code in another comment to keep this post clean and easy to read!
[1]: https://sta.sh/0lxys26jxas - What I want it to do
[2]: https://sta.sh/01bb40bktkzy - Still able to activate DB even over here
[3]: https://sta.sh/0x72tkml4u8 - Big collision areas are not problem either
well it seems I can’t add comments XD
here’s the code
Dialogue
extends Popup
var dialog = [“dialog” , “new dialog”]
var dialog_index = 0
var dialog_fin = false
func _process(_delta):
$Text_Arrow/arrow_anim.play(“arrow_anim”)
if Input.is_action_just_pressed(“ui_accept”):
popup()
load_dialog()
pass
func load_dialog():
get_tree().paused = true
if dialog_index < dialog.size():
dialog_fin = false
$Textbox/BodyText.bbcode_text = dialog[dialog_index]
$Textbox/BodyText.percent_visible = 0
$Tween.interpolate_property($Textbox/BodyText , “percent_visible”
, 0,1,1, Tween.TRANS_LINEAR , Tween.EASE_IN_OUT)
$Tween.start()
else:
queue_free()
get_tree().paused = false
dialog_index += 1
func _on_Tween_tween_all_completed() → void:
dialog_fin = true
pass # Replace with function body.
NPC
extends StaticBody2D
const DIALOG = preload(“res://Assest/Scenes/Dialgoue_test 2.tscn”)
var can_speak = false
func _ready():
pass
func _process(_delta):
$“NPC sprite_G”.play(“NPC_idle”)
func speech_loop():
var dialog = DIALOG.instance()
get_parent().add_child(dialog)
func _on_Area2D_area_entered(_area: Area2D) → void:
can_speak = true
if can_speak == true:
speech_loop()
print(“true”)
func _on_Area2D_area_exited(_area: Area2D) → void:
can_speak = false
print(“false”)