Godot Version
v4.6.2
Question
Hello! I’ve been following an old tutorial for godot-3 on how to make a dialogue system for a project and i’ve managed to update a bit of the code to godot-4’s gdscript so far, but I’ve been stuck on the tweening functionality where they make each character of the text appear in succession.
In the video the person uses these lines of code for the tweening:
$Tween.interpolate_property(label, "percent_visible", 0.0, 1.0, len(next_text) * CHAR_READ_RATE, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
$Tween.start()
which allowed them to set “percent_visible” to start at a value of 0 and then gradually increase it to 1, so it functions just as intended in the video.
In the current script “tween.tween_property” can only set the desired final value for the “visible_ratio” so I’ve opted to set it to 0 using the inspector window godot has.
const CHAR_READ_RATE : float = 0.08
@onready var dialoguecontainer: MarginContainer = $Dialoguecontainer
@onready var label: RichTextLabel = $Dialoguecontainer/MarginContainer/HBoxContainer/Label
func _ready() -> void:
hide()
add_text("•wowza!! this text is awesome!!!")
pass
func _process(_delta: float) -> void:
pass
func add_text(next_text):
label.text = next_text
show()
#creates tween
var tween = get_tree().create_tween()
#gradually reveals all letters by incrementing the visible_ratio
tween.set_ease(Tween.EASE_IN_OUT)
tween.tween_property(label, "visible_ratio", 1.0, len(next_text) * CHAR_READ_RATE).set_trans(Tween.TRANS_LINEAR)
tween.tween_callback(label.queue_free)
and it tweens just fine, up until it gets to the last charcter where it all vanishes again.
I suspect it might be something with the visible_ratio value being reset to 0 in some way, but I just don’t know what to do to fix it.
I was wondering if there is a way I could keep the visible_ratio at 1.0 once the tween is finished.