How to set varibles before add the scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MrGenie151

I’m trying to add a dialog box to my game, and I’m having trouble implementing it so I can use it with my sign. What should I do?
It keeps spitting this error at me: Invalid set index ‘dialog’ (on base: ‘PackedScene’) with value of type ‘Array’.
This is my code:

extends Area2D

export(Array, String, MULTILINE) var dialog
export(float) var textSpeed = 0.05
var canInteract = false
const dialogBox = preload("res://Assets/Objects/DialogBox.tscn")

func body_entered(body):
	if body.name == "Player":
		canInteract = true

func body_exited(body):
	if body.name == "Player":
		canInteract = false

func _ready():
	connect("body_entered",self,"body_entered")
	connect("body_exited",self,"body_exited")
	dialogBox.dialog = dialog
	dialogBox.textSpeed = textSpeed

func _input(event):
	if Input.is_action_pressed("interact") and canInteract == true:
		canInteract = false
		var dialogInstance = dialogBox.instance()
		get_parent().add_child(dialogInstance)
:bust_in_silhouette: Reply From: timothybrentwood

You can’t set variables of a PackedScene. You set the variables of the instance of the PackedScene.

func _ready():
    connect("body_entered",self,"body_entered")
    connect("body_exited",self,"body_exited")

func _input(event):
    if Input.is_action_pressed("interact") and canInteract == true:
        canInteract = false
        var dialogInstance = dialogBox.instance()
        dialogInstance.dialog = dialog
        dialogInstance.textSpeed = textSpeed
        get_parent().add_child(dialogInstance)

Note that you should also make sure to clean up the instances you create at runtime with queue_free().

I was trying that before, and it wasn’t working as no box would show up.

MrGenie151 | 2021-11-29 00:27

It might not be positioned correctly or stuff might be drawn on top of it or something along those lines. Check out the remote scene tree debugger to see exactly what’s going on while running your game:

Overview of debugging tools — Godot Engine (stable) documentation in English

timothybrentwood | 2021-11-29 15:03