0 votes

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, "domodal" In this function I call popup() then call "yield(self, "popuphide")" 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, addchild() to put it in the tree and call domodal().

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?

in Engine by (71 points)

1 Answer

–1 vote

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.

by (292 points)
edited by

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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.