Messagebox Tutorial/GameMode And MenuMode

From the Oblivion ConstructionSet Wiki
Revision as of 01:51, 15 September 2007 by imported>Haama (→‎The basics: Clarity)
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 (Choosing == 0)
    Set GMRun to 0
    If (GetInSameCell YourXMarker == 0)
      MoveTo YourXMarker
    Endif
    Return
  Elseif GMRun
    Set GMRun to 0
    Set ExitButton to 0
    Messagebox "Exiting options..."
  Elseif (Choice == -1)
    Set Choice to GetButtonPressed
    Return
  Elseif (Choice != ExitButton)
    Set ExitButton to 0
    Messagebox "Exiting options..."
  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 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.


Example code (Multiple Menus Script from the MessageBox Tutorial)

(also, please note that due to wiki limitations, the messageboxes below have been given line breaks, whereas in the CS they wouldn't have one)

Short Choosing
Short Choice



Begin onActivate
  Set Choosing to -1
  If (GetInSameCell player == 0)
    MoveTo player
  Endif
End



Begin GameMode
  If (Choosing == 0) ;meaning it shouldn't be running
    If (GetInSameCell YourXMarker == 0)
      MoveTo YourXMarker
    Endif


  Elseif (Choosing == -1) ;Display your menu
    Messagebox "Would you like to donate gold or food?" "Gold" "Food"
                                                        "Blood" "Cancel"
    Set Choosing to 1
    Set Choice to GetButtonPressed
    Return

  Elseif (Choosing == 1)
    If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
      Return
    Elseif (Choice == 0) ;Gold
      Set Choosing to -2 ;to open the Gold menu
    Elseif (Choice == 1) ;Food
      Set Choosing to -3 ;to open the Food menu
    Elseif (Choice == 2) ;Blood
      Set Choosing to -4 ;to open the Blood menu
    Elseif (Choice == 3) ;Cancel
      Set Choosing to 0 ;to close the menus
    Endif
    Return

  Elseif (Choosing == -2) ;Gold 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" 
    Set Choosing to 2
    Set Choice to GetButtonPressed
    Return

  Elseif (Choosing == 2)
    If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
    Elseif (Choice == 0) ;25
      If (player.GetGold > 25)
        Player.RemoveItem Gold001 25
        Set Choosing to 0
      Else
        Set Choosing to -99 ;a message that the player doesn't have enough
      Endif
    Elseif (Choice == 1) ; I've changed my mind
      Set Choosing to -1 ;to return to the opening menu
    Elseif (Choice == 2) ; I've changed my mind, I'll donate food
      Set Choosing to -3 ;to open the food menu
    Elseif (Choice == 3) ; I've changed my mind, I'll donate blood
      Set Choosing to -4 ;to open the blood menu
    Elseif (Choice == 4) ; I've changed my mind, I won't donate anything
      Set Choosing to 0 ;to close the menus
    Endif
    Return

  Elseif (Choosing == -3) ;Food menu
    Messagebox "How much food would you like to donate?" "Options"
                                                         "More Options"
                                                         ...
                                                         "Cancel"
    Set Choosing to 3
    Set Choice to GetButtonPressed
    Return

  Elseif (Choosing == 3)
    If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
    Elseif (Choice == 0)  ;Options
...
    Elseif (Choice == 9)  ;Cancel
      Set Choosing to 0
    Endif
    Return


    Elseif (Choosing == -99) ;Player-doesn't-have-enough menu
      Messagebox "You don't have enough."
      Set Choosing to 99
      Set Choice to GetButtonPressed
      Return

    Elseif (Choosing == 99)
    If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
    Elseif (Choice == 0) ;player pressed "Done", return to main menu
      Set Choosing to -1
    Endif
    Return


  Endif
End