Bug in ShowMessageDialog before first frame passes

Started by stewbasic, December 17, 2014, 04:34:14 PM

Previous topic - Next topic

stewbasic

I have a map containing a core with the following script.


:GameLoaded
if(<-done eq0)
"Blah" "OK" "Cancel" ShowMessageDialog
1 ->done
endif


When the map loads, the message shows as expected. However, after clicking "OK" or "Cancel" it shows again, repeating indefinitely. The strangest part is: if I leave the map and load a different map with a dialog message, the "Blah" message will again show indefinitely after showing the correct (other map's) message once. This persists until I quit and relaunch CW3.

The condition seems to be that the message is shown before 1 game frame passes. I get the same behaviour if the core has OperateWhilePaused(TRUE) and the dialog is triggered before the map is unpaused (which is the use case I actually care about). I can work around this by unpausing for 1 frame before ShowMessageDialog.

Grayzzur

Try doing it outside of :GameLoaded? That seems an odd place to me to be showing a dialog. It's before the game runs the first frame.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

stewbasic

I tried to make a minimal example (hence the oddness). My actual script involves a dialog box triggered when the player clicks something, and runs while the game is paused; the player may legitimately want to click the button before first unpausing the game. A minimal example with the same structure would be:


once @Awake endonce
if (GetMouseButtonDown(0))
# Omitted: Check mouse is on button
"Blah" "OK" "Cancel" ShowMessageDialog
endif

:Awake
OperateWhilePaused(TRUE)


I think you are right that the problem is because the game hasn't run the first frame. As I mentioned, the bug can be worked around by adding


if(IsPaused)
UnpauseGame
Delay(1)
PauseGame
endif


before ShowMessageDialog.

Grayzzur

That's probably it then. The ability to run cores while paused came later, and Virgil warned us there might be issues with it. This sounds like one of them, and I think your workaround is probably the best approach to dealing with it.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

knucracker

Yeah, the operate while paused stuff was an after thought and it isn't real pretty.  The message dialog system is also a little bit complex, so the combination of the two... I'm not surprised.

stewbasic