Ah, welcome to the sparsely documented world of
It sparsely documented because it gets complex quickly; some would say it gets weird. It also quickly leads to discussions of signal processing, thread lifetimes, multiprocessing, stack frames, iterators, generators, and coroutines. Then it gets complicated when you add multiple processes.
The most common issues with yield, in my limited experience:
Signal storms: I start to process a signal. In processing a signal, I end up calling something that generates another of the signals I am trying to process. I often ignore the repeated signals. I use a local variable if I want just that instance from restarting (
if _guard: return; _guard = true; ....; guard = false; return..). Alternately, a global variable or
mutex can be a global guard.
Yield semantics are unclear: Make a scene with just a 2D node and a button named TheButton. Ponder this code and explain why it prints 1, 2, 3, 4 in order:
print("4, on the second press")
print("2, after pressing")
print("3, immediately after 2")
Failure to Pause: Modal boxes pause the rest of the game. There is a tutorial, but the short answer is to set the pause mode of your modal to
Process and use
get_tree().paused = true while dealing with your modal. This suspends the per frame process and physics process used by both your code and most controls, timers, and animators.
That all said, I can see some errors in your code along these lines. I suggest you keep paring down code until it works with small snippets. If this for your debugging, you might cheat and try for a button that just advances the frame.
I look forward to any expansion on the
yield semantics, and whatever you learn trying to get past this problem.