Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: stewbasic on December 17, 2014, 04:34:14 PM

Title: Bug in ShowMessageDialog before first frame passes
Post by: stewbasic on December 17, 2014, 04:34:14 PM
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.
Title: Re: Bug in ShowMessageDialog before first frame passes
Post by: Grayzzur on December 17, 2014, 08:34:33 PM
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.
Title: Re: Bug in ShowMessageDialog before first frame passes
Post by: stewbasic on December 18, 2014, 05:02:25 AM
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.
Title: Re: Bug in ShowMessageDialog before first frame passes
Post by: Grayzzur on December 18, 2014, 11:15:45 AM
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.
Title: Re: Bug in ShowMessageDialog before first frame passes
Post by: knucracker on December 18, 2014, 12:14:57 PM
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.
Title: Re: Bug in ShowMessageDialog before first frame passes
Post by: stewbasic on December 18, 2014, 04:03:54 PM
Fair enough, I'll work around then. Thanks!