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

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Haama
imported>Haama
(Removed from category)
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
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)
This is a subsection of the [[MessageBox Tutorial]], and uses [[MessageBox_Tutorial#Activator_Script|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 [[MessageBox_Tutorial#Example_script|example script]] (I would suggest opening it in a new tab/window).
<pre>Short GMRun
<pre>Short GMRun
Short ExitButton
Short ExitButton
Line 16: Line 27:


Begin GameMode
Begin GameMode
   If (Choosing == 0)
   If Working
     Set GMRun to 0
    Set Working to 1
     If (GetInSameCell YourXMarker == 0)
 
       MoveTo YourXMarker
    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
    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
   Endif
End
End
Line 58: Line 72:
                                                         "Cancel"
                                                         "Cancel"
End</pre>
End</pre>
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)
<pre>Short Choosing
Short Choice
Begin onActivate
  Set Choosing to -1
  If (GetInSameCell player == 0)
    MoveTo player
  Endif
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.
*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
<pre>    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"</pre>
you'll need to add a second ExitButton (changes marked)
<pre>short ExitButton2;<-------------------------------------------------------New line
...


Begin GameMode
Begin GameMode
   If (Choosing == 0) ;meaning it shouldn't be running
   If Working
     If (GetInSameCell YourXMarker == 0)
...
      MoveTo YourXMarker
    Elseif GMRun
    Endif
      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
   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"
     Messagebox "Would you like to donate gold or food?" "Gold" "Food"
                                                         "Blood" "Cancel"
                                                         "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
   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"
     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've changed my mind, I'll donate Food"
             "I've changed my mind, I'll donate Blood"
             "I've changed my mind, I'll donate Blood"
             "I've changed my mind, I won't donate anything"  
             "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
   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"
     Messagebox "How much food would you like to donate?" "Options"
                                                         "More Options"
                                                         "Exit Menu"
                                                         ...
                                                         ...
                                                         "Cancel"
                                                         "Cancel"</pre>
    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</pre>
<br>[[User:Haama|Haama]] 03:43, 14 June 2007 (EDT)

Latest revision as of 18:07, 3 June 2008

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"