For now project use thread
Dialogue.gd
func _ready():
if has_method(default_starting_event):
Rakugo.set_current_dialogue(self)
thread = Thread.new()
step_semaphore = Semaphore.new()
thread.start(self, default_starting_event) <= create new thread
default_starting_event is a function name, like this one
func hello_world():
say(null, "Hello, World !")
step()
say(null, "What is your name ?")
player_name = ask("Paul")
We can see step()
func step():
if thread and thread.is_active():
Rakugo.step()
step_semaphore.wait()
If we refer to doc https://docs.godotengine.org/en/stable/tutorials/performance/threads/using_multiple_threads.html#semaphores , step_semaphore.wait()
need to be used in thread. I don't know if it executed in thread but "it's work".
In Godot we can't kill a thread. So to quit properly, all thread need to be finished.
We can see _exit_tree()
func _exit_tree():
if thread:
step_semaphore.post()
thread.wait_to_finish()
But thread need to be finished, so hello_world() must be executed in whole.
So we run game, step() it's called, we want to quit, _exit_tree() is called, step_semaphore is released and go on. say(), ask(). And there we have a problem.
We can see ask()
func ask(default_answer:String):
if thread and thread.is_alive():
Rakugo.ask(default_answer)
ask_yield()
step_semaphore.wait() <= there
return ask_return
return null
In ask(), step_semaphore.wait()
is executed. After we want to close. And in _exit_tree() we waiting with thread.wait_to_finish()
. So it's never ended...
Law is "In Godot we can't kill a thread. So to quit properly, all thread need to be finished". So we can think first, add a flag in all function say(), ask(), notify(), menu(), etc... to check if a thread want to ended and do nothing. But we can add what we want in hello_world() because it's gdscript, save, pop things, make beautiful effect, etc... And them be executed !