Messagebox Tutorial/GameMode And MenuMode

From the Oblivion ConstructionSet Wiki
Revision as of 02:33, 15 September 2007 by imported>Haama (→‎The script: Variable-loaded method)
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

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

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

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
    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
    Set Working to 1
  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

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.