Tween Error "started with no tweeners"

Godot Version

4.2.1

Question

I took the following code for a textbox from a tutorial and I’m getting an error. I don’t have much knowledge about tweens yet.
Can someone help me?

Error: started with no tweeners

extends CanvasLayer

const CHAR_READ_RATE = 0.05

@onready var textbox_container = $TextboxContainer
@onready var start_symbol = $TextboxContainer/MarginContainer/HBoxContainer/Start
@onready var end_symbol = $TextboxContainer/MarginContainer/HBoxContainer/End
@onready var label = $TextboxContainer/MarginContainer/HBoxContainer/Label
@onready var tween = get_tree().create_tween()

enum State {
READY,
READING,
FINISHED
}

var current_state = State.READY
var text_queue =

func _ready():
hide_textbox()
queue_text(“Test”)
queue_text(“Hallo!!”)
queue_text(“Hier ist ein sehr langer Beispieltext, um zu schauen ob der Textumbruch funktioniert”)

func _process(_delta):
match current_state:
State.READY:
if !text_queue.is_empty():
display_text()
State.READING:
if Input.is_action_just_pressed(“ui_cancel”):
tween.kill()
label.visible_characters = - 1.0
end_symbol.text = “>”
change_state(State.FINISHED)
State.FINISHED:
if Input.is_action_just_pressed(“ui_cancel”):
change_state(State.READY)
hide_textbox()

func queue_text(next_text):
text_queue.push_back(next_text)

func hide_textbox():
start_symbol.text = “”
end_symbol.text = “”
label.text = “”
textbox_container.hide()

func show_textbox():
start_symbol.text = “*”
textbox_container.show()

func display_text():
tween = get_tree().create_tween()
var next_text = text_queue.pop_front()
label.text = next_text
label.visible_characters = 0.0
change_state(State.READING)
show_textbox()
tween.tween_property(label, “visible_characters”, len(next_text), len(next_text) * CHAR_READ_RATE).from(0)
tween.connect(“finished”, on_tween_finished)
end_symbol.text = “…”

func on_tween_finished():
end_symbol.text = “>”
change_state(State.FINISHED)

func change_state(next_state):
current_state = next_state

Apparently if you create a tween as you do with onready, but dont use it, it throws this error, since it doesnt have anything to do

If I remove the line, an error occurs.
Line 33: tween.kill()
It can’t find a tween in the function.

it tries to kill a tween that doesnt exist. Try doing this:

var tween: Tween
.
.
. # line 33
if tween != null:
    tween.kill()

The same Error :frowning:

replace “tween != null” with “tween.is_valid()”

Once again the same error

I think you’ll need both actually.

if is_instance_valid(tween) and tween.is_valid(): # how valid can you get lol
    tween.kill()
1 Like

what about:

if tween:
    tween.kill()

usually if it’s empty it won’t go through or null

1 Like

Usually that is equivalent to

if tween != null:
    tween.kill()

I would love if it was a special case for tween though

not sure why but for data like:

var data = 0
var data1 =  ""

if data:
    pass
if data1:
    pass

it won’t go through this 2 if statements this 2 datas aint null but are “emtpy”

1 Like

In that case int, float, and I think string can’t be null. int is implicitly data > 0 like in C/C++ and string is implicitly not data1.is_empty().

1 Like

The error is still there despite the changes. The scene runs smoothly, but the error keeps occurring.

What is the error exactly? Are we getting the wrong line, I’m thinking this is for the “ui_cancel” action

1 Like

I added the left mouse button and placed it there. The error still occurs.

It shouldn’t be the same error at this point, did you change the definition like @herrspaten said?

# was: @onready var tween = get_tree().create_tween()
var tween: Tween
2 Likes

It works! Thank you very much for the help :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.