Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | alexgmihai |
I have a RPG dialogue box scene on autoload. I use it to display dialogue on all game scenes. The problem is that if i do this:
Dialog.Dialog = [“messagle1”, “message2”]
Dialog.start(“Person”)
Dialog.Dialog = [“messagle1”, “message2”]
Dialog.start(“Person”)
The code will not wait for the first function to finish and then put the new messages in the variable Dialog. Do you have any idea on how i could solve this?
The full code for the dialogue script:
extends CanvasLayer
var Dialog = [
‘default text’,
‘default text2’,
]
var dialog_count = 0
var finished = false
func _ready():
$Control.visible = false
func _process(delta):
if Input.is_action_just_pressed(“ui_accept”):
if increment():
display_diag()
if Input.is_action_just_pressed(“ui_right”):
if increment():
display_diag()
if Input.is_action_just_pressed(“ui_left”):
if decrement():
display_diag()
func start(persoana):
finished = false
$Control/RichTextLabel2.bbcode_text = persoana
dialog_count = 0
display_diag()
func finished():
$Control.visible = false
finished = true
func increment():
if dialog_count < Dialog.size()-1:
dialog_count += 1
return true
else:
finished()
func decrement():
if dialog_count > 0:
dialog_count -=1
return
else:
finished()
func display_diag():
$Control.visible = true
$Control/RichTextLabel.bbcode_text = Dialog[dialog_count]
$Control/RichTextLabel.percent_visible = 0
$Control/Tween.interpolate_property(
$Control/RichTextLabel, “visible_characters”, 0, 187, 7,
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT
)
$Control/Tween.start()
func _on_Tween_tween_completed(object, key):
pass