MessageBox Tutorial/Ensuring Your Menu Is Seen

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

This is a subsection of the MessageBox Tutorial, and uses this script as a base. The following code may or may not require certain aspects of that script to work, however the information should prove useful for any script (it will take a bit of care to make it work, though).


For this tutorial, you will want to centralize your decision catching.


If another menu is shown before the player makes a decision, that other menu will overwrite your menu. That is, your menu will be erased and the new menu will be shown instead. This leads to a few problems:

  • The player can no longer respond to your menu
  • Your script will continue to run, once a frame, at least these lines:
  if (Choosing == 0)
...
  Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
    Set Choice to GetButtonPressed

until the menu is started up again (activated again).

  • Your script won't run through the exit if (Choosing == 0)


To avoid this, add a timer (well, counter, but same principle). If GetButtonPressed returns the player's decision (> -1), then your menu was responded to. If it remains -1 after the timer runs out, then another menu must have overwritten yours, and you can make yours pop up again. The timer will be long enough to allow the other menu script to finish before showing your previous menu again.

To do all this, replace:

  Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
    Set Choice to GetButtonPressed

with (due to wiki limitations, the large if test has been given line breaks, whereas in the CS it would all be on one line)

short MessageCounter
...
  Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
    if (MessageCounter < 30)
      set Choice to GetButtonPressed
      if (Choice == -1)
        if (MenuMode 1001 == 0)
          if (MenuMode 1004 == 0) && (MenuMode 1005 == 0) && (MenuMode 1006 == 0) &&
             (MenuMode 1010 == 0) && (MenuMode 1011 == 0) && (MenuMode 1013 == 0) &&
             (MenuMode 1015 == 0) && (MenuMode 1016 == 0) && (MenuMode 1017 == 0) &&
             (MenuMode 1018 == 0) && (MenuMode 1019 == 0) && (MenuMode 1020 == 0) &&
             (MenuMode 1021 == 0) && (MenuMode 1024 == 0) && (MenuMode 1038 == 0) &&
             (MenuMode 1039 == 0) && (MenuMode 1044 == 0) && (MenuMode 1045 == 0) &&
             (MenuMode 1046 == 0) && (MenuMode 1047 == 0) && (MenuMode 1057 == 0)
             ;These are options menus, etc. where GetButtonPressed won't return anything
            set MessageCounter to (MessageCounter + 1)
          endif
        else ;MenuMode 1001
          set MessageCounter to 0
        endif
      else ;Choice > -1
        set MessageCounter to 0
      endif
    else ;Display menu again
      set Choosing to -(Choosing)
      set MessageCounter to 0
      message "Trying menu again..."
    endif

and when you exit the script, reset the MessageCounter to 0, as such:

begin GameMode
  if Working
    Set Working to 1

    if (Choosing == 0)
      Set Working to 0
      Set MessageCounter to 0

And now I'm sure you want to know the details of what all that actually does. When another menu overwrites yours, any response the player makes will be caught by the other script's GetButtonPressed, but not by your script's GetButtonPressed. That means Choice will always be -1. So, these extra lines will start a countdown once the player has left the menu screen (MenuMode 1001). If 30 frames pass and GetButtonPressed is still returning -1 then your menu is reset (with set Choosing to -(Choosing). The countdown won't run when the player presses <ESC> and looks through their options (that's what that whole mess of if (MenuMode 1004 == 0)... is for). This won't disturb other menus, because the countdown is reset whenever a new menu is displayed. So, once the other mod's menus are out of the way, your menu will be shown again.