real-ezTheDev / GodotEzDialoguePlugin

MIT License
146 stars 12 forks source link

end_of_dialogue_reached signal firing (potentially) incorrectly #27

Open torbenvanassche opened 1 month ago

torbenvanassche commented 1 month ago

I looked at the code in the dialogue_reader and may have found a potential bug that I don't quite know how to work around. I have a simple setup with a single node for testing and the signal is firing after every next() call. image

This result makes sense given the _process function saids

if _pending_choice_actions.is_empty():
    response.eod_reached = true
    end_of_dialogue_reached.emit()
break

I print the first line, call next() and the end_of_dialogue_reached is emitted. I would expect it to only fire after the next line is printed (which also happens)

Am I using this plugin wrong? Could you point out how I can fix this code so I can properly use the signal?

class_name DialoguePrinter extends Printer

@export var dialogue: JSON;
var state: Dictionary = {};
var dialogue_handler: EzDialogue;

func _ready():
    dialogue_handler = EzDialogue.new();
    add_child(dialogue_handler)

    dialogue_handler.dialogue_generated.connect(_on_dialogue_generated)
    dialogue_handler.end_of_dialogue_reached.connect(clear)
    dialogue_handler.start_dialogue(dialogue, state);
    print_done.connect(_on_print_done.bind(0))

func _on_dialogue_generated(response: DialogueResponse):
    self.show_text(response.text)

func _on_print_done(index: int = 0):
    dialogue_handler.next(index)
torbenvanassche commented 1 month ago

Adding that I can work around the issue by just calling next() and checking the string for empty. Either I am missing something or this is a solution to the problem :)

real-ezTheDev commented 4 weeks ago

Haha thanks for filing this. It is actually very tricky issue I've been messing with. Personally, I've been using empty string AND choice as end signal, but also I've added a new flag called eod_reached in the response that you can use to read as final dialogue.. ill keep this open and continue documenting/fixing so that it's more intuitive.