#Invalid access to property or key 'finished_displaying' on a base object of type 'MarginContainer'

1 messages · Page 1 of 1 (latest)

raw pendant
#

Hello! I am following this tutorial and in my script i get the error shown.

Invalid access to property or key 'finished_displaying' on a base object of type 'MarginContainer'

im using Godot 4.3

this is the tutorial i am watching:
https://www.youtube.com/watch?v=1DRy5An_6DU

this is my code

extends Node


@onready var text_box_scene = preload("res://Scenes/dialogbox.tscn")

var dialog_lines: Array[String] = []

var current_line_index = 0

var text_box
var text_box_position: Vector2

var is_dialog_active = false
var can_advance_line = false

func start_dialog(position: Vector2, lines: Array[String]):
    if is_dialog_active:
        return
    
    dialog_lines = lines
    text_box_position = position
    _show_text_box()
    
    is_dialog_active = true

func _show_text_box():
    text_box = text_box_scene.instantiate()
    text_box.finished_displaying.connect(_on_text_box_finished_displaying)
    get_tree().root.add_child(text_box)
    text_box.global_position = text_box_position
    text_box.display_text(dialog_lines[current_line_index])
    can_advance_line = false

func _on_text_box_finished_displaying():
    can_advance_line = true

func _unhandled_input(event):
    if (
        event.is_action_pressed("advance_dialog") &&
        is_dialog_active &&
        can_advance_line
    ):
        text_box.queue_free()
        
        current_line_index += 1
        if current_line_index >= dialog_lines.size():
            is_dialog_active = false
            current_line_index = 0
            return
        
        _show_text_box()

any help is appreciated

dusty cliff
#

Can I assume that you do indeed have a dialogbox.tscn in your Scenes folder, and that it has the relevant signal in its script?

raw pendant
#

It is. the script is also a global autoload

dusty cliff
#

In my experience, I usually see that error when I'm improperly accessing a variable or method.

For example, if I were to try to call a method without the brackets at the end, it thinks its a variable. It'll throw a similar error. Is the signal in the code for the root node of the dialogbox?

raw pendant
#

which signal? the one in the brackets?

dusty cliff
#

The one called 'finished displaying' that you're connecting to

raw pendant
#

im not quite sure. i see what your talking about but i dont think it's connected to anything

dusty cliff
#

That's a problem then

#

You're trying to connect a signal that doesn't exist

raw pendant
#

ok wait. there was a script attached to the root node of the scene being this

extends MarginContainer


@onready var label = $MarginContainer/Label
@onready var timer = $LetterDisplayTimer

const MAX_WIDTH = 256

var text = ""
var letter_index = 0

var letter_time = 0.03
var space_time = 0.06
var punctuation_time = 0.2

signal finish_displaying()

func display_text(text_to_display: String):
    text = text_to_display
    label.text = text_to_display
    
    await resized
    custom_minimum_size.x = min(size.x, MAX_WIDTH)
    
    if size.x > MAX_WIDTH:
        label.autowrap_mode = TextServer.AUTOWRAP_WORD
        await resized
        await resized
        custom_minimum_size.y = size.y
    
    global_position.x -= size.x / 2
    global_position.y -= size.y + 24
    
    label.text = ""
    _display_letter()

func _display_letter():
    label.text += text[letter_index]
    
    letter_index += 1
    if letter_index >= text.length():
        finish_displaying.emit()
        return
    
    match text[letter_index]:
        "!", ".", ",", "?":
            timer.start(punctuation_time)
        " ":
            timer.start(space_time)
        _:    
            timer.start(letter_time)


func _on_letter_display_timer_timeout() -> void:
    _display_letter()

dusty cliff
#

remove the brackets from the signal declaration

raw pendant
#

i removed it but i still get an error. im assuming your talking about this

dusty cliff
#

Same error with the brackets removed?

raw pendant
#

Invalid access to property or key 'finished_displaying' on a base object of type 'MarginContainer (dialogbox.gd)'.

dusty cliff
#

so, just to confirm you're declaring the signal like so: signal finished_displaying correct?

#

Two things I noticed. First is the brackets. Not needed. Second, is that you have two different signal names.

#

finish_displaying and finished_displaying

raw pendant
#

that was the issue. i didnt notice that i put finished_displaying and finish_displaying tysm