nathanhoad / godot_dialogue_manager

A powerful nonlinear dialogue system for Godot
MIT License
2.04k stars 161 forks source link

Using inline [do func()] makes the function run twice if you skip_typing() midway #591

Closed DinoMC closed 1 month ago

DinoMC commented 2 months ago

Describe the bug

I have a dialogue that uses [do my_func()] in the middle of a line. This function use await, so the dialogue pauses while it's running.

I use the portrait example Balloon, modified so that the player can click the dialogue or press a button to trigger skip_typing() for the current line of dialogue if they read faster than the typing speed I set (similar to the standard way dialogue works in a lot of RPGs : first press = have the whole line of dialogue appear instantly, second press = go to next line.)

If the player do that while my_func is running (ie. during the "await"), the dialogue will call my_func() again AND skip_typing correctly, rather than just skip_typing.

Affected version

To Reproduce Steps to reproduce the behavior:

  1. Have the following dialogue : "Character: Blablabla. [do my_func()] Blabla."

  2. Have the following function :

    func my_func(): 
    await get_tree().create_timer(3.0).timeout; 
    print("test")
  3. In your balloon, add the following code to the beginning of your _on_balloon_gui_input(event) function :

    if event is InputEventMouseButton and event.is_pressed() and event.button_index == 1:
    dialogue_label.skip_typing()
  4. Run the scene and trigger the dialogue. While the character is waiting (for the function to be done) after saying Blablabla, click the balloon.

  5. After 3 seconds you should see "test" being printed twice in the Output tab.

Expected behavior When running skip_typing() after the dialogue already called the function, it should simply skip to the end of the line as usual, without calling the function again.

PS I fixed my issue by using "do!" since it didn't matter in my case that the dialogue waited for the function to run (and if it did there's other workarounds) so this bug isn't an issue for me, I'm just reporting it to inform about it.