Want suggestion on Dialouge system where text display speed can vary

Godot Version

4.X

Question

I’m planning on learning writing dialogue system.

First step: Make a text box, and characters display themselves one by one.

while rich_label.visible_ratio < 1.0:
    rich_label.visible_characters += 1
    await get_tree().create_timer(0.3).timeout

This should do.

Second: Makes it so that text goes faster while holding button.

while rich_label.visible_ratio < 1.0:
    rich_label.visible_characters += 1
    var char_gap: float = 0.5 - (0.4 * int(Input.is_action_pressed("ui_confirme")))
    await get_tree().create_timer(char_gap).timeout

This would work.

Third: Makes it go faster or slower on commend, for example:
“[char_gap=.8]I’m now talking…[char_gap=.1]REALLY FAST!!!”
Annnnnd I have no idea how to do that.
How does apps reads bbcode anyway? Do they instantly check for close bracket when they see an open one?

It’s still on theory crafting stage, just looking for some general direction guidance so I can start easier.

Thanks for reading.

You may have to parse the dialogue for custom commands that cannot be handled by bbcodes. This type-writer effect might be possible through a custom bbcode/RichTextEffect.

I would recommend using a Timer node instead of create_timer so often

while rich_label.visible_ratio < 1.0:
    rich_label.visible_characters += 1
    var char_gap: float = 0.5 - (0.4 * int(Input.is_action_pressed("ui_confirme")))

    $Timer.wait_time = char_gap
    await $Timer.timeout
2 Likes
@tool
class_name RichTextTypeWriter
extends RichTextEffect

var bbcode := "type_writer"

func _process_custom_fx(char_fx: CharFXTransform) -> bool:
	var char_speed: float = char_fx.env.get("char_speed", .2)
	char_fx.color.a = 0
	if char_fx.elapsed_time > char_fx.range.x * char_speed:
		char_fx.color.a = 1
	
	return true

Well, this works…Though I’m not sure how do I add sfx, and how do I change speed mid sentence since all characters process individually and timing would mess up.
This is a direction I can work with, so thanks for suggestion.

1 Like

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