0 votes

Im trying to make a dialogue system for NPC's. However this error comes at the end when i put in the code

get_parent().add_child(_dialogue)

Here is the complete code for the NPC script.

extends Area2D

var can_interact = false
const _dialogue = preload("res://Game Mechanic Scenes/DialogueBox.tscn")

func _on_InteractionPoint_body_entered(body):
    if body.name == "Player":
        $Label.visible = true
        can_interact = true

func _on_InteractionPoint_body_exited(body):
    if body.name == "Player":
        $Label.visible = false
        can_interact = false

 func _input(_event):
    if Input.is_action_just_pressed("Interact") and can_interact == true:
        $Label.visible = false
        var newDialogue = _dialogue.instance()
        get_parent().add_child(_dialogue)

The Error: Parser Error: At "add_child()" call, argument 1. The passed argument's type (PackedScene) doesn't match the function's expected argument type (Node).

What have I done wrong?

Godot version 3.2.3 Stable Official
in Engine by (20 points)

1 Answer

0 votes
Best answer

You need to use the instance of the _dialogue var and not the const itself

var newDialogue = _dialogue.instance()
get_parent().add_child(newDialogue)
by (4,128 points)
selected by

Ah okay. Thanks!

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.