Godot Version
Godot 4.4.1
Question
I have a dialog system that has been working fine. Currently, you can skip through the dialog by pressing the interact key in the middle of the text showing animation. This will will immediately skip to the next line of dialog.
extends CanvasLayer
signal dialog_start
signal dialog_end
@onready var name_label: Label = $Control/Panel/VBoxContainer/NameLabel
@onready var dialog_label: Label = $Control/Panel/VBoxContainer/DialogLabel
@export var dialog_lines : Array = []
@export var text_speed : float = 50.0
var line_number = 0
var showing_dialog = false
var tween : Tween = null
func _ready():
dialog_start.connect(run_dialog)
self.hide()
func _process(_delta):
if Input.is_action_just_pressed("interact") and Global.current_state == Global.States.DIALOG and showing_dialog:
play_next_line()
line_number += 1
func run_dialog():
if dialog_lines.size() > 0:
Global.current_state = Global.States.DIALOG
showing_dialog = true
self.show()
line_number = 0
play_next_line()
func end_dialog():
Global.current_state = Global.States.PLAYABLE
showing_dialog = false
self.hide()
dialog_end.emit()
func assign_dialog():
var dialog_line = dialog_lines[line_number]
dialog_line = dialog_line.split(":")
var dialog_name = dialog_line[0]
var dialog_text = dialog_line[1]
name_label.text = dialog_name
dialog_label.text = dialog_text
func play_next_line():
if line_number < dialog_lines.size():
if tween and tween.is_running():
tween.kill()
assign_dialog()
var character_count = dialog_label.get_total_character_count()
dialog_label.visible_ratio = 0
tween = create_tween()
tween.tween_property(dialog_label, "visible_ratio", 1, character_count / text_speed)
else:
end_dialog()
Instead, during the animation I want it to stop playing and show the entire line when interact is pressed. And then, when interact is pressed again, move to the next line of dialog. I tried to edit the logic in the _process function to make this work.
func _process(_delta):
if Input.is_action_just_pressed("interact") and Global.current_state == Global.States.DIALOG and showing_dialog:
if tween and tween.is_running():
tween.stop()
dialog_label.visible_ratio = 1
else:
play_next_line()
line_number += 1
This works, however every time I initiate dialog, the first line pops up twice, the first time being fully shown, and then after that the rest of the dialog works as intended. I’m new to programming so I’m not sure why this is happening, and how I can change the logic so that doesn’t happen.