Godot Version
3.5.3
Question
I’m trying to do a dialogue system by my own because i don’t understand how to use the dialogue systems addons of the community, they are kind of hard to implement in a project (at least for me
).
My idea of how to make that dialogue system is by a CSV file that has the character name and the dialog text (I’ll make a CSV per scene, environment, action, whatever) and by that get all the information that i need for the dialogue.
So, I’m having a problem on these lines:
if !_dialogue_file == null:
if _i < dialog_data.size():
character = dialog_data[_i]["Character"]
dialogue = dialog_data[_i]["Dialogue"]
var _dialogue = dialogue.replace("'","")
character_name_text.text = character
dialogue_label.bbcode_text = _dialogue
finished_dialogue = false
if Input.is_action_just_pressed("Interact"):
if finished_typing:
_i += 1
if !interact_key_was_pressed:
dialogue_label.percent_visible = 0
start_typing_delay.start()
elif _i == dialog_data.size():
finished_dialogue = true
my idea is to say that finished_dialog is true when _i has the same value as the one returned by dialog_data.size() (5 in my case) but as in programming zero is a valid number then it triggers the problem that the dialog is supposed to be finished but according to elif it is not like that (that is to say that when _i is four the dialog should be finished), since the CSV file has four lines (discarding the one that says “Character, Dialogue” ) and my idea is that when _i is four finished_dialog is true.
Btw, here is the whole code of the dialogue system in case if you want to review it
extends Control
onready var dialogue_label = $"Dialogue box/Text2"
onready var character_name_text = $Character_name_text
onready var animation_player = $AnimationPlayer
onready var interact_key = $"VBoxContainer/Interact key"
onready var _i_text = $VBoxContainer/_i
onready var finished_typing_text = $VBoxContainer/finished_typing
onready var start_typing_text = $VBoxContainer/start_typing
onready var is_typing_text = $VBoxContainer/is_typing
onready var no_moer_lines_text = $VBoxContainer/no_more_lines
onready var cant_call_exit_animation_label = $VBoxContainer/cant_call_exit_animation
var character_count : float
var interact_key_was_pressed := false
var is_typing := false
var cant_call_enter_animation := false
var cant_call_exit_animation := false
var animation_finished := false
var finished_typing : bool = false
var start_typing : bool = false
var file_already_readed := false
var finished_dialogue : bool = true
var start_typing_delay := Timer.new()
var finished_typing_delay := Timer.new()
var _delta : float
var _i : int = 0
var _text : String
var _dialogue_file
var character : String
var dialogue : String
var dialog_data : Array
func _ready() -> void:
Engine.target_fps = 60
start_typing_delay.one_shot = true
start_typing_delay.wait_time = 0.25
start_typing_delay.connect("timeout",self,"_on_start_typing_delay_timeout")
add_child(start_typing_delay)
finished_typing_delay.one_shot = true
finished_typing_delay.wait_time = 0.25
finished_typing_delay.connect("timeout",self,"_on_finished_typing_delay_timeout")
add_child(finished_typing_delay)
dialogue_label.percent_visible = 0
character_count = dialogue_label.bbcode_text.length()
func _process(delta: float) -> void:
_delta = delta
if start_typing:
type_dialogue()
if !_dialogue_file == null:
if _i < dialog_data.size():
character = dialog_data[_i]["Character"]
dialogue = dialog_data[_i]["Dialogue"]
var _dialogue = dialogue.replace("'","")
character_name_text.text = character
dialogue_label.bbcode_text = _dialogue
finished_dialogue = false
if Input.is_action_just_pressed("Interact"):
if finished_typing:
_i += 1
if !interact_key_was_pressed:
dialogue_label.percent_visible = 0
start_typing_delay.start()
elif _i == dialog_data.size():
finished_dialogue = true
if Input.is_action_just_pressed("Interact"):
interact_key_was_pressed = true
if file_already_readed == false:
read_dialogue_file("res://Nuevo Hoja de cálculo OpenDocument.csv")
if is_typing:
dialogue_label.percent_visible = 1
if finished_dialogue:
dialogue_label.text = ""
if finished_typing == true and finished_dialogue:
if !cant_call_exit_animation:
animation_player.play("dialogue_exit")
print("a")
else:
interact_key_was_pressed = false
interact_key.text = "interact key: " + str(interact_key_was_pressed)
_i_text.text = "_i: " + str(_i)
start_typing_text.text = "start_typing: " + str(start_typing)
finished_typing_text.text = "finished_typing: " + str(finished_typing)
is_typing_text.text = "is_typing: " + str(is_typing)
no_moer_lines_text.text = "no more lines: " + str(finished_dialogue)
cant_call_exit_animation_label.text = "cant_call_exit_animation_label: " + str(cant_call_exit_animation)
func read_dialogue_file(dialogue_file: String):
var file = File.new()
_dialogue_file = dialogue_file
if file.open(dialogue_file, File.READ) == OK:
while !file.eof_reached():
var line = file.get_line()
var columns = line.split(";")
if columns.size() == 2:
character = columns[0]
dialogue = columns[1]
dialog_data.append({"Character": character, "Dialogue":dialogue})
file_already_readed = true
file.close()
else:
file_already_readed = false
print("hubo un error al tratar de leer el archivo: ", dialogue_file)
start_dialogue()
func start_dialogue():
animation_player.play("dialogue_enter")
func type_dialogue():
if dialogue_label.percent_visible < 1:
for i in range(dialogue_label.percent_visible, 1):
dialogue_label.percent_visible += (1/character_count) * (_delta * (64^100))
is_typing = true
finished_typing = false
else:
finished_typing = true
is_typing = false
start_typing = false
func _on_AnimationPlayer_animation_finished(anim_name: String) -> void:
if anim_name == "dialogue_enter" and !animation_finished:
animation_finished = true
cant_call_enter_animation = true
start_typing_delay.start()
if anim_name == "dialogue_exit":
cant_call_enter_animation = false
cant_call_exit_animation = true
dialogue_label.bbcode_text = ""
func _on_start_typing_delay_timeout():
start_typing = true
func _on_finished_typing_delay_timeout():
start_typing = false
finished_typing = true