How to control typing speed in Typewriter effect in RichTextLabel using code?

Godot Version

v4.1.1.stable.official [bd6af8e0e]

Question

I’m making an RPG style game, it has a lot of text, I’m using “RichTextLabel” with BBCode to format the text. So far I’ve managed to get by, but I’m not able to place the “Typewriter” effect correctly on the text when I run the game.
Below is the script:

extends RichTextLabel

var fulltext = text
var currenttext = ''
var currentindex = 0
var typingspeed = 0.1

func _ready():
	set_process(true)
	get_tree().create_timer(typingspeed).timeout.connect(self._on_timeout)

func _process(_delta):
	if currentindex < len(fulltext):
		currenttext += fulltext[currentindex]
		self.set_text(currenttext)
		currentindex += 1

func _on_timeout():
	_process(0)

For some reason, when I change the value of the typingspeed variable nothing happens. What I wanted was for the text to appear faster, or slower, as I changed this variable.

Can someone help me?!
Thank you very much in advance!

look at this solution, should be what you are looking for

1 Like

I wonder if it is possible to do this kind of typewriter effect using a tween

I think tween was removed, because in the version I’m in (v4.1.1) it doesn’t exist.

Thank you for the example and sources for study!
I managed to solve the problems thanks to your help!

1 Like

This really helped me, it gave me even more than I needed! wow
Thank you very much!

Note: I chose the other answer because it is more focused on the problem of this post, but your answer also serves as a solution!

It doesn’t exist as a node in Godot 4.x, but you can create one like so:

var tween = get_tree().create_tween()
1 Like

It is, I did something like :

var typing_tween:Tween = get_tree().create_tween()
typing_tween.tween_property(RichTextLabelNode, "visible_characters", RichTextLabelNode.get_total_character_count(), typing_speed)