Difference between revisions of "Messagebox Tutorial/GameMode And MenuMode"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Qazaaq
(Added to scripting tutorials)
imported>Haama
(Temporarily Removed from Scripting Tutorials Category)
Line 182: Line 182:
   Endif
   Endif
End</pre>
End</pre>
[[Category:Scripting_Tutorials]]

Revision as of 11:56, 27 June 2007

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, if your script is too large you won't be able to have two huge blocks of menu-y goodness. So, here's how to fake a menu system with a small GameMode block: (note that these are the changes from the second script)

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

There are a few things to note here:


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


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