Messagebox Tutorial/GameMode And MenuMode

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).


Intro[edit | edit source]

Most of the time, you'll want to run the menu script in both GameMode and MenuMode blocks. For the most part, this won't be a problem - just copy the one block into the other (make any necessary changes: delete non-menu code, change loop labels, etc.). However, there is a size limit to your script, and if it's too large it won't compile/save. To get around this, you can use a small GameMode block to start the MenuMode block, which has the real menu system.

The basics[edit | edit source]

A menu will be displayed from GameMode. Once this menu pops up, the MenuMode block will run, which will overwrite the GameMode menu with the correct menu. Once the player makes their selection, GameMode will start again and the button will be caught in GameMode. If another menu needs to be displayed, or any more MenuMode processing needs to happen, the GameMode menu will be displayed, again running the MenuMode block. This continues until the player selects an option that will exit the menu.

The script[edit | edit source]

Note that these are the changes from the example script (I would suggest opening it in a new tab/window).

Short GMRun
Short ExitButton



begin onActivate
...
  if (MenuMode == 0)
    set GMRun to 1
  endif
...
end



Begin GameMode
  If Working
    Set Working to 1

    If (Choosing == 0)
      Set GMRun to 0
      Set Working to 0
      ;Add anything that needs to be re-initialized
    Elseif GMRun
      Set GMRun to 0
      Set ExitButton to 0
      Messagebox "Exiting options..."
    Elseif (Choice == -1)
      Set Choice to GetButtonPressed
    Elseif (Choice != ExitButton)
      Set ExitButton to 0
      Messagebox "Exiting options..."
    Elseif (Choice == ExitButton)
      Set Choosing to 0
    Endif
  Endif
End



Begin MenuMode
...
  Elseif (Choosing == -1) ;Display your menu
    Set ExitButton to 3 ;This is the button that will exit the menu
    Messagebox "Would you like to donate gold or food?" "Gold" "Food"
                                                        "Blood" "Cancel"
...
  Elseif (Choosing == -2) ;Gold menu
    Set ExitButton to 4 ;same here, 5th option exits the menu
    Messagebox "How much Gold would you like to donate?" "25"
            "I've changed my mind" "I've changed my mind, I'll donate Food"
            "I've changed my mind, I'll donate Blood"
            "I've changed my mind, I won't donate anything"
...
  Elseif (Choosing == -3) ;Food menu
    Set ExitButton to 9 ;same here, 10th option exits the menu
    Messagebox "How much food would you like to donate?" "Options"
                                                         "More Options"
                                                         ...
                                                         "Cancel"
End

A few more notes[edit | edit source]

  • Basically, this works by firing up a menu while in GameMode. The menu will start up the MenuMode block, which will then display the correct menu. The menu I've chosen to display for GameMode is "Exiting options…". I've done this as, if the player happens to see this menu, something has gone wrong and when the player clicks "Done" the options menu will close (I have yet to see this menu, by the way).
  • GMRun ensures that the first menu (from the GameMode block) is shown to get everything started. From then on, a new menu will be displayed whenever the player has selected an option that is supposed to bring up another menu.
  • For each menu, you will need to set the ExitButton. This is important so there won't be a menu displayed from the GameMode block after the player has decided to exit. Set it to -2 if there aren't any options that will let the player exit the menu.
  • If you have more than one button that will exit the menu, you will need to add an extra ExitButton variable for each one. Use them the same as the original.
    • For instance, if you change the last menu (in the above example) to have 2 exits
    Elseif (Choosing == -3) ;Food menu
    Set ExitButton to 9 ;same here, 10th option exits the menu
    Messagebox "How much food would you like to donate?" "Options"
                                                         "Exit Menu"
                                                         ...
                                                         "Cancel"

you'll need to add a second ExitButton (changes marked)

short ExitButton2;<-------------------------------------------------------New line
...

Begin GameMode
  If Working
...
    Elseif GMRun
      Set GMRun to 0
      Set ExitButton to 0
      Set ExitButton2 to 0 ;<-----------------------------------------------New line, 2nd exit same as 1st if only 1 exit
      Messagebox "Exiting options..."
...
    Elseif (Choice != ExitButton) && (Choice != ExitButton2) ;<-------------Changed line, test for 2nd exit
      Set ExitButton to 0
      Set ExitButton2 to 0 ;<-----------------------------------------------New line
      Messagebox "Exiting options..."
    Elseif (Choice == ExitButton) || (Choice == ExitButton2) ;<-------------Changed line, test for 2nd exit
...
Begin MenuMode
...
  Elseif (Choosing == -1) ;Display your menu
    Set ExitButton to 3
    Set ExitButton2 to 3 ;<--------------------------------------------------New line
    Messagebox "Would you like to donate gold or food?" "Gold" "Food"
                                                        "Blood" "Cancel"
...
  Elseif (Choosing == -2) ;Gold menu
    Set ExitButton to 4
    Set ExitButton2 to 4 ;<--------------------------------------------------New line
    Messagebox "How much Gold would you like to donate?" "25"
            "I've changed my mind" "I've changed my mind, I'll donate Food"
            "I've changed my mind, I'll donate Blood"
            "I've changed my mind, I won't donate anything"
...
  Elseif (Choosing == -3) ;Food menu
    Set ExitButton to 9
    Set ExitButton2 to 1 ;<--------------------------------------------------New line, set to the new/2nd exit
    Messagebox "How much food would you like to donate?" "Options"
                                                         "Exit Menu"
                                                         ...
                                                         "Cancel"