How do I create a modal dialog?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Allen Kennedy Jr.

What is a modal dialog? It’s a window of some sort that does a minimum of 2 things:

  1. Disallows input to anywhere else in the program until it is closed
  2. Blocks program execution until closed.

I’ve by trying for hours to use combinations of the functions, “popup” “yield” and “Show modal” to get this to work.

This is as close as I can get:
my WindowDialog scene has a function called, “do_modal” In this function I call popup() then call “yield(self, “popup_hide”)” I have a button in the scene that calls hide() Yes, the “Exclusive” checkbox is checked.

Else where in my program, I instance the MyWindowDialog, add_child() to put it in the tree and call do_modal().

I would expect execution to stop at the yield function and resume when I hide the pop-up. What actually happens is that execution returns immediatley from the do_modal() function to where I had created and added the dialog - causing issues as the data that the dialog would create has yet to be created.

THe documentation indicates that the Yield function pauses execution, but this appears to not be the case. In fact the Yield function seems to return from the executing function to the next in the call stack, and allows re-entry to the called function from the yield function, at a later time point when the signal is met. Which causes the call stack to be executed and unwound twice.

So, Failing on requirement 2 of a modal.

Further… given that execution return… lets say I can detect that and skip the errors… The Dialog does show up, BUT it still allows input to the rest of the scene. I have the arrow keys mapped to moving the camera, and pressing the arrow keys while the dialog is up Still moves the camera despite Exclusive being checked and supposedly being ‘modal’

So that fails requirement 1 of a modal.

Any ideas how to actually make a real live modal dialog?

:bust_in_silhouette: Reply From: MaaaxiKing

yield only pauses the function in which it was called. Do get_tree().paused = true and remove your yield lines and in the Inspector set Pause (under Node) to Process (on every Node you want it to process while the game is paused). When hide() is called you have to do get_tree().paused = false.

I gave this a try. It does resolve requirement 1. But it does nothing regarding requirement 2. The doModal function still returns immediately and I do not have the data I need to continue the game like logic.

Allen Kennedy Jr. | 2020-06-06 14:22

You could either write the code which should not be executed in if get_tree().paused == false:or maybe try with adding your old yield(self, "popup_hide") again.

MaaaxiKing | 2020-06-06 15:02