Visibleratio dialoguebox idea

i tried to make a gameboyadvance dialoguebox for my game using the visible ratio property of ‘richtextlabel’. Even though the dialogue box works but it only works for the last dialogue and skips all the initial dialogues… please help me with this, here’s the script:

extends Control


# Called when the node enters the scene tree for the first time.
func _ready():
	var base = $"."
	text_box.visible = false

@onready var text_box = $TextBox
@onready var text_label = $TextBox/TextLabel

func PlayText(Text):
	is_dialogue_running = true
	text_box.visible = true
	text_label.text = Text
	var tween = create_tween().tween_property(text_label, "visible_ratio", 1, 3)
	await tween.finished
	wait(3)
	text_label.visible_ratio = 0
	
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass

var is_dialogue_running = false

func wait(durationX):
	get_tree().create_timer(durationX).timeout
	
func StopDisplay():
	text_box.visible = false
	text_label.text = ""

func _on_timer_timeout():
	PlayText("Hey there i am a Timmy and i lost my candy") #this line gets skipper
	wait(10)
	PlayText("Where can i buy more?") #this line plays

func _on_button_pressed():
	text_box.visible = false
	text_label.text = ""

Your wait() method won’t work like this, which is probably the reason that the dialogue is skipped entirely.
You’ll need to use await to wait untill the timer has run out, and then also to wait for the asynchronous method to finish, so try replacing

func wait(durationX):
	get_tree().create_timer(durationX).timeout

with

func wait(durationX):
	await get_tree().create_timer(durationX).timeout

and replace

	wait(3)

with

	await wait(3)

in your PlayText() method.

2 Likes

Thanks alot that worked well and everything works like a charm

1 Like

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