i’ve been following a pretty old youtube tutorial to get this system to work but eventually i got it down, all i had to do now is link interacting with NPC to make the dialogue box show up with the NPC’s dialogue in it. i’ve tried everything but i cannot get it to work, debugged all i could and even asked the big ol’ chatGPT to no avail.
for now i have the NPC as an area2D which when entered and pressing the interact button emit a signal which the text area picks up and sets up a dialogue for it to be shown, but when i run the game i get this error
here is my code, some help would be truly appreciated(apologies if its hard to read, im a bit of a beginner)
You are creating a Tween in the _ready() function unnecessarily without any Tweeners. Remove line 27 and it should work fine, unless there are any other issues in the code.
Also, line 76 is useless, because you create a Tween and then override it with another Tween 2 lines later.
thank you! the error is gone but unfortunately the dialogue box still doesnt appear
edit: this is the code for the npc, im assuming the error is from here because the signal reacting function doesnt seem to be working (i used a print to check)
Try to use the preformatted text functionality with ``` to paste your code instead of screenshots, it’s easier to read, copy, etc.
Definitely this piece of code is a source of problem. What this piece of code means is that you would need to press the “interact” action EXACTLY at the same time (down to a single frame) as the body entered the area, in order to emit the signal, which is close to impossible.
Not sure what was your intention, but I will take a guess that you wanted to emit the spoke signal at the time that “interact” action is pressed, but only if the body is within the area. You need to slightly rearrange your code to do it, I’d do it this way:
signal spoke
var is_body_within_area: bool
func _on_body_entered(_body: Node2D) -> void:
is_body_within_area = true
func _on_body_exited(_body: Node2D) -> void:
is_body_within_area = false
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("interact") and is_body_within_area:
spoke.emit()
Just make sure to connect both body_entered and body_exited signals to their functions accordingly.
I’m assuming there are no other “bodies” that can enter this area, because if there are - they will trigger this function as well, which might not be what you want. You’d then need to additionally check if the entering/exiting body is the player.
Let me know if you have any further issues and if not - mark my response as a solution so others know it’s resolved in case they ever encounter a similar issue.
there’s a huge improvement! now the dialogue actually appears, much thanks! although it also infinitely loops after it finishes…
no worries im sure i can figure it out
edit: i figured it out! since the interact button and enter both go to the next message, but interact also…well, interacts, when you go to the next message via the interact button it just goes to the first message again, all i had to do is make a bool variable that checks if the NPC has already been interacted with and only emit the message if that variable is false.
thank you so much for the help and patience i’ve been struggling with this for DAYS, may your woes be few and your days be many!