Difference between revisions of "MessageBox Tutorial"

2,510 bytes added ,  10:37, 15 April 2010
no edit summary
imported>Haama
(→‎Activator Disadvantages: Changing over to fake-loaded method)
imported>Darkness X
 
(28 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]|opt0=[[OBSE]]}}
==Intro==
==Intro==
Most MessageBox mistakes stem from adapting a script that works in some cases, but not in more complex situations. To prevent this, this tutorial will work through several almost-working scripts, showing you their pitfalls. By the end, you'll have an all-purpose script that can be used and expanded for any situation, and know why every line is needed. We'll start out with some of the basic mechanics of the MessageBox and related functions, followed by common mistakes in complex scripts, and then the all-purpose script and how to set it up. Finally, we'll go through how to use the script to easily move between multi-layered menus, and some extras that you can tack on to it.
Most MessageBox mistakes are made when simple scripts are used as a base for more complex menu scripts. To prevent this, this tutorial will work towards a single all-purpose script that can be used and expanded for any situation. By the end, you will know the problems that can pop-up in a menu script, how to prevent them, and why every line of the all-purpose script is needed.


Note that there are 4 mediums to attach a menu script to: Activators, Quests, Tokens (Object scripts on items in the player's possession), and Spells (or Magic Effect scripts). This article will focus mainly on activators, but the other methods, their differences, and how to set them up will be discussed on other pages (coming soon). Activators are the focus as they are easier to use in most situations (see [[MessageBox_Tutorial#In_which_I_try_to_convince_you_to_use_an_activator|"In which I try to convince you to use an activator"]] for the reasons, though it's highly suggested to read the article first).
We'll start out with some of the basic mechanics of the MessageBox and related functions, followed by common mistakes in complex scripts, and then the all-purpose script and how to set it up. Finally, we'll go through how to use the script to easily move between multi-layered menus, and some extras that you can tack on to it.


 
Note that there are 4 mediums to attach a menu script to: Activators, Quests, Tokens (Object scripts on items in the player's possession), and Spells (or Magic Effect scripts). This article will focus mainly on activators, but the other methods, their differences, and how to set them up will be discussed on other pages. Activators are the focus as they are easier and safer to use in most situations (see [[MessageBox_Tutorial#In_which_I_try_to_convince_you_to_use_an_activator|"In which I try to convince you to use an activator"]] for the reasons, though it's highly suggested to read the article first).
===In the middle of being rewritten===
All of the information is accurate, but some rewriting (mostly for clarity) is still required. Sections left:
Different methods for menu script (Tokens)<br>
Moving between multiple menus<br>
Extras
 
The best method for Spells is still being discussed, but the information is accurate.


==Basic Mechanics of MessageBox and Related Functions==
==Basic Mechanics of MessageBox and Related Functions==
Line 183: Line 177:
   endif
   endif
end</pre>
end</pre>
Note that each menu has a pair of corresponding numbers: Main menu, -1/1; Armor menu, -10/10; Weapon menu, -11/11. When you set Choosing to the corresponding number, that menu will be shown. You can find more information in the [[MessageBox Tutorial#Moving Between Multiple Menus]] section.
Note that each menu has a pair of corresponding numbers: Main menu, -1/1; Armor menu, -10/10; Weapon menu, -11/11. When you set Choosing to the corresponding number, that menu will be shown. You can find more information in the [[MessageBox Tutorial#Moving Between Multiple Menus|Moving Between Multiple Menus]] section.


===Running the same choice for multiple frames===
===Running the same choice for multiple frames===
Line 242: Line 236:


There are 4 mediums you could use for the script: Quest, Activator, Tokens (Object scripts on items in the player's possession), and Spells (or Magic Effect scripts). Each has their own advantages and disadvantages, but it's suggested you use an activator.
There are 4 mediums you could use for the script: Quest, Activator, Tokens (Object scripts on items in the player's possession), and Spells (or Magic Effect scripts). Each has their own advantages and disadvantages, but it's suggested you use an activator.
====Activator Advantages====
====Activator Advantages====
* Activators can keep persistent variables that other scripts can use (unlike tokens and spells)
* Activators can keep persistent variables that other scripts can use (unlike tokens and spells)
** Quest variables can be reset by using 'StartQuest' when the quest is already running (and there are reports of quests requiring resetting if a variable is added in a mod's update).
** Quest variables can be reset by using 'StartQuest' when the quest is already running (and there are reports of quests requiring resetting if a variable is added in a mod's update).
** Activators are safe from Oblivion cell resets. These resets will return a container's inventory to it's original state, objects to their start location, etc., but the variables on the activator will remain the same.
* There's a clear beginning to it ([[OnActivate]], unlike quests)
* There's a clear beginning to it ([[OnActivate]], unlike quests)
* It's easy and fast to start (harder for a quest)
* It's easy and fast to start (harder for a quest)
Line 253: Line 249:


====Activator Disadvantages====
====Activator Disadvantages====
* They need to be [[Loaded]] to run every frame (more below)
* They need to be [[Loaded]] to run every frame. The easiest way to keep it loaded is to set one of it's own variables every frame. Setting a variable loads an object into memory, as if it were in the same cell as the player. Like this:
* They can run even when not around the player (though only for a single frame, but enough to cause [[:Category:Tidbits#When_do_remote_activators_run.3F|problems]]).
<pre>short Working
* Both require an extra line of coding (which conveniently work together)
...
* One thing that should be mentioned - activators are safe from Oblivion cell resets. These resets will return a container's inventory to it's original state, objects to their start location, etc., but the variables on the activator will remain the same.
begin GameMode
...
  set Working to 1
...
</pre>
* Their script can run even when not around the player (though only for a single frame, but enough to cause [[:Category:Tidbits#When_do_remote_activators_run.3F|problems]]). To solve this problem, set a flag variable (for this tutorial, ''Working'') to 1 when the script should be running, and 0 when it should end. Use an '''if''' test to check ''Working'', like so:
<pre>short Working
...
begin onActivate
...
  set Working to 1
end


====Other methods====
begin GameMode
* [[MessageBox_Tutorial:_Quest_Scripts|Quests]]
   if Working
* Tokens
    if (Choosing == 0)
* [[MessageBox_Tutorial:_Spell_Scripts|Spells]]
      set Working to 0
 
...
====Extra coding for activators====
* They need to be [[Loaded]], or moved to the player's cell, to use effectively
** This requires extra coding, to keep them around the player, and move them back when finished.
 
To move them to the player:
<pre>begin onActivate
   set Choosing to -1
  if ((GetInSameCell player) == 0)
    MoveTo player
   endif
   endif
end</pre>
end</pre>
Set Working to 0 when you wish to keep the script from running.
* These solutions work hand in hand. When the script should be running, and Working is 1, set Working to 1 at the beginning of every frame to keep it loaded for the next frame. When it's 0, don't set any variables and the activator will be unloaded, preventing the script from errantly running. Combining them looks like this:
<pre>short Working
...
begin onActivate
...
  set Working to 1
end
begin GameMode
  if Working
    set Working to 1


To move them away from the player when finished you'll also need your own remote cell with your own XMarker in it (YourXMarker), and this section of script:
    if (Choosing == 0)
<pre>begin GameMode
      set Working to 0
  if (Choosing == 0)
      return
     if ((GetInSameCell YourXMarker) == 0)
     elseif (Choosing == 1)
      MoveTo YourXMarker
...
     endif
     endif
...</pre>
----
* They can run even when not around the player (though only for a single frame, but enough to cause [[:Category:Tidbits#When_do_remote_activators_run.3F|problems]]).
** This requires a bit of extra coding, to prevent them from doing something unexpected.
Use an extra variable to mark that the menu has been initialized (variables set, other objects moved, etc.):
<pre>begin onActivate
  set Choosing to -1
;  StopQuest InterferingQuest ;This is just an example of why you need the Reset variable
  set Reset to 1
  if ((GetInSameCell player) == 0)
    MoveTo player
   endif
   endif
end
end</pre>


begin GameMode
====Other methods====
  if (Choosing == 0)
* [[MessageBox_Tutorial/Quest_Scripts|Quests]]
    if Reset
* [[MessageBox_Tutorial/Token_Scripts|Tokens]]
;      StartQuest InterferingQuest ;Again, this is just an example
* [[MessageBox_Tutorial/Spell_Scripts|Spells]]
      set Reset to 0
    endif
    if ((GetInSameCell YourXMarker) == 0)
      MoveTo YourXMarker
    endif
...</pre>
Note that the activator will be moved away from the player regardless of needing to be reset. When it's not in use, it should be moved away to prevent unnecessary '''if''' tests on the activator from running (''if (Choosing == 0)'', ''If Reset'').


===What you'll need===
===What you'll need===
You'll need to set up some objects for the next script: an invisible activator, an XMarker, and your own cell:
You'll need to set up some objects for the next script: an invisible activator, an XMarker, and your own cell:


===Your own cell===
===Your own cell===
Line 320: Line 308:
#Select "Duplicate Cell"
#Select "Duplicate Cell"
#Rename your new cell to something you'll remember (and don't worry about the lack of floors, it'll work just fine)
#Rename your new cell to something you'll remember (and don't worry about the lack of floors, it'll work just fine)
===XMarker===
#Scroll down the "Object Window"
#Select Statics
#Scroll to the bottom
#Double-click your cell in the "Cell View" window to open it in the "Render Window"
#Drag the XMarker from the "Object Window" into the "Render Window"
#Right-click the red X (XMarker) in the "Render Window"
#Select edit.
#In the "Reference Editor ID" box, give it a name you'll remember (in these examples it will be "YourXMarker").


===Activator===
===Activator===
#Select an activator in the "Object Window"
#Select an activator in the "Object Window"
#*It needs to be an activator. Statics can't have scripts, [[:Category:Troubleshooting#Activating_a_Container_(including_NPC)|NPCs and containers can cause a CTD if they have a scripted item in their inventory]], and items can be picked up.
#*It needs to be an activator. Statics can't have scripts, [[Crashes#Activating_a_Container_(including_NPC)|NPCs and containers can cause a CTD if they have a scripted item in their inventory]], and items can be picked up.
#Edit the name
#Edit the name
#Press enter (or select ok in the edit menu)
#Press enter (or select ok in the edit menu)
Line 341: Line 317:
#Drag your new activator into the "Render Window"
#Drag your new activator into the "Render Window"
#Right-click it
#Right-click it
#Give it a "Reference Editor ID"
#Give it a "Reference Editor ID". This is the reference you'll use to start up the menu, so make it something memorable.
#Mark it as "Persistent Reference" and "Initially Disabled"
#Mark it as "Persistent Reference" and "Initially Disabled"
#Place the following script on your new activator
#Place the following script on your new activator
Line 351: Line 327:
===Activator Script===
===Activator Script===
<pre>scn YourMenuScript
<pre>scn YourMenuScript
Short Working
Short Choosing
Short Choosing
Short Choice
Short Choice
short Reset




Line 359: Line 335:
Begin onActivate
Begin onActivate
   Set Choosing to -1
   Set Choosing to -1
   Set Reset to 1
   Set Working to 1
  If (GetInSameCell player == 0) ;always keep it near the player
    MoveTo player
  Endif
End
End


Line 368: Line 341:


Begin GameMode
Begin GameMode
   If (Choosing == 0) ;meaning it shouldn't be running
   If Working
    If Reset
    Set Working to 1
 
    If (Choosing == 0) ;meaning it shouldn't be running
      Set Working to 0
       ;Add anything that needs to be re-initialized,
       ;Add anything that needs to be re-initialized,
       ;  or that you changed in the onActivate block that needs to be reset
   
       Set Reset to 0
    Elseif (Choosing == -1) ;Display your menu
     Endif
       Messagebox "Which option?" "First Option" "Second Option" ... "Tenth Option"
    If (GetInSameCell YourXMarker == 0)
      Set Choosing to 1
       MoveTo YourXMarker
       Set Choice to -1
    Endif
     Elseif (Choosing == 1) ;Catch the player's decision
      If (Choice == -1) ;No choice yet
        Set Choice to GetButtonPressed
      Elseif (Choice == 0) ;First Option
        ;run your code for the first decision
        Set Choosing to 0 ;to finish up
       Elseif (Choice == 1) ;Second Option
        ;run your code for the second decision
        Set Choosing to 0 ;to finish up
;...
;      Elseif (Choice == 9) ;Tenth Option
        ;run your code for the tenth decision
;        Set Choosing to 0 ;to finish up


 
       Endif
  Elseif (Choosing == -1) ;Display your menu
    Messagebox "Which option?" "First Option" "Second Option" ;...
    Set Choosing to 1
    Set Choice to -1
 
  Elseif (Choosing == 1) ;Catch the player's decision
    If (Choice == -1) ;No choice yet
       Set Choice to GetButtonPressed
    Elseif (Choice == 0) ;First Option
      ;run your code for the first decision
      Set Choosing to 0 ;to finish up
    Elseif (Choice == 1) ;Second Option
      ;run your code for the second decision
      Set Choosing to 0 ;to finish up
;...
;Further illustrations of more options
;    Elseif (Choice == #) ;Nth Option
      ;run your code for the nth decision
;      Set Choosing to 0
;    Elseif (Choice == 9) ;Final/Tenth Option
      ;run your code for the tenth decision
;      Set Choosing to 0
     Endif
     Endif
   Endif
   Endif
End</pre>
End</pre>
You can start your menus from any script with <pr>YourActivatorsReferenceEditorID.Activate player, 1</pre>.
You can start your menus from any script with <pre>YourActivatorsReferenceEditorID.Activate player, 1</pre>.


==Moving Between Multiple Menus==
==Moving Between Multiple Menus==
Line 432: Line 398:
===Example script===
===Example script===
Here's several examples of menu switching: (also, please note that due to wiki limitations, the messageboxes below have been given line breaks, whereas in the CS they would be on one line)
Here's several examples of menu switching: (also, please note that due to wiki limitations, the messageboxes below have been given line breaks, whereas in the CS they would be on one line)
<pre>Short Choosing
<pre>Short Working
Short Choosing
Short Choice
Short Choice
short Reset






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


Line 449: Line 412:


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


    If (Choosing == 0) ;meaning it shouldn't be running
      Set Working to 0
      ;Add anything that needs to be re-initialized,


  Elseif (Choosing == -1) ;Display your menu
    Elseif (Choosing == -1) ;Display your menu
    Messagebox "What would you like to donate?" "Gold" "Food" "Blood" "Cancel"
      Messagebox "What would you like to donate?" "Gold" "Food" "Blood" "Cancel"
    Set Choosing to 1
      Set Choosing to 1
    Set Choice to -1
      Set Choice to -1
  Elseif (Choosing == 1)
    Elseif (Choosing == 1)
    If (Choice == -1) ;No choice yet
      If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
        Set Choice to GetButtonPressed
    Elseif (Choice == 0) ;Gold
      Elseif (Choice == 0) ;Gold
      Set Choosing to -11 ;to open the Gold menu
        Set Choosing to -11 ;to open the Gold menu
    Elseif (Choice == 1) ;Food
      Elseif (Choice == 1) ;Food
      Set Choosing to -12 ;to open the Food menu
        Set Choosing to -12 ;to open the Food menu
    Elseif (Choice == 2) ;Blood
      Elseif (Choice == 2) ;Blood
      Set Choosing to -13 ;to open the Blood menu
        Set Choosing to -13 ;to open the Blood menu
    Elseif (Choice == 3) ;Cancel
      Elseif (Choice == 3) ;Cancel
      Set Choosing to 0 ;to close the menus
        Set Choosing to 0 ;to close the menus
    Endif
      Endif


  Elseif (Choosing == -11) ;Gold menu
    Elseif (Choosing == -11) ;Gold menu
    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 11
      Set Choosing to 11
     Set Choice to -1
      Set Choice to -1
     Elseif (Choosing == 11)
      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 -12 ;to open the food menu
      Elseif (Choice == 3) ; I've changed my mind, I'll donate blood
        Set Choosing to -13 ;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


  Elseif (Choosing == 11)
    Elseif (Choosing == -12) ;Food menu
    If (Choice == -1) ;No choice yet
      Messagebox "How much food would you like to donate?" "An apple"
                                                          "Two apples"
                                                          ...
                                                          "Cancel"
      Set Choosing to 12
       Set Choice to GetButtonPressed
       Set Choice to GetButtonPressed
     Elseif (Choice == 0) ;25
     Elseif (Choosing == 12)
       If (player.GetGold > 25)
      If (Choice == -1) ;No choice yet
         Player.RemoveItem Gold001 25
        Set Choice to GetButtonPressed
      Elseif (Choice == 0) ;An Apple
        If (player.GetItemCount Apple)
          player.RemoveItem Apple 1
        Else
          set Choosing to -99 ;Go to special 'Not enough' menu
        Endif
        Set Choosing to -1 ;To return to main menu
       Elseif (Choice == 1)  ;Two Apple
        If ((player.GetItemCount Apple) > 1)
          player.RemoveItem Apple 2
        Else
          set Choosing to -99 ;Go to special 'Not enough' menu
         Endif
        Set Choosing to -1 ;To return to main menu
;...
      Elseif (Choice == 9)  ;Cancel
         Set Choosing to 0
         Set Choosing to 0
      Else
        Set Choosing to -99 ;a message that the player doesn't have enough
       Endif
       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 -12 ;to open the food menu
    Elseif (Choice == 3) ; I've changed my mind, I'll donate blood
      Set Choosing to -13 ;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


  Elseif (Choosing == -12) ;Food menu
    Elseif (Choosing == -13) ;Blood menu
    Messagebox "How much food would you like to donate?" "Options"
      Messagebox "How much blood would you like to donate?" "1 HP"
                                                        "More Options"
                                                            "2 HP"
                                                        ...
                                                            ...
                                                        "Cancel"
                                                            "Cancel"
    Set Choosing to 12
      Set Choosing to 13
    Set Choice to GetButtonPressed
 
  Elseif (Choosing == 3)
    If (Choice == -1) ;No choice yet
       Set Choice to GetButtonPressed
       Set Choice to GetButtonPressed
     Elseif (Choice == 0)  ;Options
     Elseif (Choosing == 13)
...
      If (Choice == -1) ;No choice yet
    Elseif (Choice == 9)  ;Cancel
        Set Choice to GetButtonPressed
      Set Choosing to 0
      Elseif (Choice == 0)  ;1 HP
    Endif
        player.ModAV Health -1 ;don't actually use this, just an easy example
    Return
        set Choosing to -1 ;to return to the main menu
 
      Elseif (Choice == 1)  ;2 HP
        player.ModAV Health -2 ;don't actually use this, just an easy example
        set Choosing to -1 ;to return to the main menu
;...
      Elseif (Choice == 9)  ;Cancel
        Set Choosing to 0
      Endif


     Elseif (Choosing == -99) ;Player-doesn't-have-enough menu
     Elseif (Choosing == -99) ;Player-doesn't-have-enough menu
Line 526: Line 517:
       Set Choosing to 99
       Set Choosing to 99
       Set Choice to GetButtonPressed
       Set Choice to GetButtonPressed
     Elseif (Choosing == 99)
     Elseif (Choosing == 99)
    If (Choice == -1) ;No choice yet
      If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
        Set Choice to GetButtonPressed
    Elseif (Choice == 0) ;player pressed "Done", return to main menu
      Elseif (Choice == 0) ;player pressed "Done", return to main menu
      Set Choosing to -1
        Set Choosing to -1
      Endif
     Endif
     Endif
   Endif
   Endif
End</pre>
End</pre>


==Extras==
==Extras==
That will take care of most menu systems you'll ever want to create. However, there is still more functioniality you can add to your menus. From here, you can either get it all by using the following script, or pick and choose using the mini-tutorials:
That will take care of most menu systems you'll ever want to create. However, there is still more functioniality you can add to your menus. From here, you can either get it all by using the following script, or pick and choose using the mini-tutorials:
<br>[[MessageBox_Tutorial:_Centralized_Decision_Catching|Centalizing your decision catching]]
<br>[[MessageBox_Tutorial/Centralized_Decision_Catching|Centalizing your decision catching]]
<br>[[Messagebox_Tutorial:_Centralizing_Your_Menu_Exits|Centralizing your menu exits]] (Required and implemented for activator scripts)
<br>[[Messagebox_Tutorial/GameMode_And_MenuMode|Running menus in both GameMode and MenuMode when your script is too large]]
<br>[[Messagebox_Tutorial:_GameMode_And_MenuMode|Running menus in both GameMode and MenuMode when your script is too large]]
<br>[[MessageBox_Tutorial/Ensuring_Your_Menu_Is_Seen|Ensuring your menus are seen]]
<br>[[MessageBox_Tutorial:_Ensuring_Your_Menu_Is_Seen|Ensuring your menus are seen]]
<br>[[Messagebox_Tutorial/Set_Variables|Allowing the player to set a variable to any number]]
<br>[[Messagebox_Tutorial:_Set_Variables|Allowing the player to set a variable to any number]]
<br>[[MessageBox_Tutorial/External_Menu_Selection|Controlling the menu system via external scripts]]
<br>[[MessageBox_Tutorial:_External_Menu_Selection|Controlling the menu system via external scripts]]


==Applying it all==
==Applying it all==
Line 554: Line 539:
<pre>scn YourMenuScript
<pre>scn YourMenuScript


Short Working
Short Choosing
Short Choosing
Short Choice
Short Choice
;Centralized Menu Exiting variable
Short Reset


;GameMode and MenuMode variables
;GameMode and MenuMode variables
Line 565: Line 548:


;Ensuring Your Menu Is Read variables
;Ensuring Your Menu Is Read variables
Float MessageTimer
Short MessageCounter
Short MessageButton






Begin onActivate
Begin onActivate
   If (Choosing >= 0)
   If (Choosing >= 0) ;Controlling the menu system via external scripts
     Set Choosing to -1
     Set Choosing to -1
   Endif
   Endif
   Set Reset to 1
   Set Working to 1
   If (MenuMode == 0)
  Set MessageCounter to 0 ;Ensuring your menus are seen
   If (MenuMode == 0) ;Running menus in both GameMode and MenuMode
     Set GMRun to 1
     Set GMRun to 1
  Endif
  If (GetInSameCell player == 0) ;always keep it near the player
    MoveTo player
   Endif
   Endif
End
End
Line 585: Line 565:




Begin GameMode
Begin GameMode ;Running menus in both GameMode and MenuMode
   If (Choosing == 0)
   If Working
    Set GMRun to 0
    Set Working to 1
    If (GetInSameCell YourXMarker == 0)
 
       MoveTo YourXMarker
    If (Choosing == 0)
    Endif
      Set GMRun to 0
     Return
      Set Working to 0
  Elseif GMRun
       Set MessageCounter to 0 ;Ensuring your menu is seen
    Set GMRun to 0
      ;Add anything that needs to be re-initialized
    Set ExitButton to 0
     Elseif GMRun
    Messagebox "Exiting options..."
      Set GMRun to 0
  Elseif (Choice == -1)
      Set ExitButton to 0
    If (MessageTimer > 0) || (MessageCounter > 0)
      Messagebox "Exiting options..."
      Set Choice to GetButtonPressed
    Elseif (Choice == -1) ;Ensuring your menus are seen
      If (Choice > -1)
      if (MessageCounter < 30)
        Return
        set Choice to GetButtonPressed
      Endif
        if (Choice == -1)
      If (MenuMode 1001 == 0)
          if (MenuMode 1001 == 0)
        If (MenuMode 1004) || (MenuMode 1005) || (MenuMode 1006) ||
            if (MenuMode 1004 == 0) && (MenuMode 1005 == 0) && (MenuMode 1006 == 0) &&
          (MenuMode 1010) || (MenuMode 1011) || (MenuMode 1013) ||
              (MenuMode 1010 == 0) && (MenuMode 1011 == 0) && (MenuMode 1013 == 0) &&
          (MenuMode 1015) || (MenuMode 1016) || (MenuMode 1017) ||
              (MenuMode 1015 == 0) && (MenuMode 1016 == 0) && (MenuMode 1017 == 0) &&
          (MenuMode 1018) || (MenuMode 1019) || (MenuMode 1020) ||
              (MenuMode 1018 == 0) && (MenuMode 1019 == 0) && (MenuMode 1020 == 0) &&
          (MenuMode 1021) || (MenuMode 1024) || (MenuMode 1038) ||
              (MenuMode 1021 == 0) && (MenuMode 1024 == 0) && (MenuMode 1038 == 0) &&
          (MenuMode 1039) || (MenuMode 1044) || (MenuMode 1045) ||
              (MenuMode 1039 == 0) && (MenuMode 1044 == 0) && (MenuMode 1045 == 0) &&
          (MenuMode 1046) || (MenuMode 1047) || (MenuMode 1057)
              (MenuMode 1046 == 0) && (MenuMode 1047 == 0) && (MenuMode 1057 == 0)
          Return
              set MessageCounter to (MessageCounter + 1)
        Else
            endif
          Set MessageTimer to (MessageTimer - GetSecondsPassed)
          else ;MenuMode 1001
          Set MessageCounter to (MessageCounter - 1)
            set MessageCounter to 0
        Endif
          endif
      Else ;MenuMode 1001
         else ;Choice > -1
         Set MessageTimer to 1
          set MessageCounter to 0
        Set MessageCounter to 45
         endif
         Return
       else ;Display menu again
       Endif
        set Choosing to -(Choosing)
    Else ;Display menu again
        set MessageCounter to 0
      Message "Trying menu again..."
        message "Trying menu again..."
       Set Choosing to -(Choosing)
      endif
    Elseif (Choice != ExitButton)
       Set ExitButton to 0
       Messagebox "Exiting options..."
       Messagebox "Exiting options..."
    Elseif (Choice == ExitButton)
      Set Choosing to 0
     Endif
     Endif
  Elseif (Choice != ExitButton)
    Set ExitButton to 0
    Messagebox "Exiting options..."
   Endif
   Endif
End
End
Line 634: Line 615:


Begin MenuMode
Begin MenuMode
   If (Choosing == 0)
   If Working
    If Reset
    Set Working to 1
       ;reset whatever you need to
 
       Set Reset to 0
    If (Choosing == 0)
    Endif
       Set GMRun to 0 ;Running menus in both GameMode and MenuMode
    If (GetInSameCell YourXMarker == 0)
       Set Working to 0
       MoveTo YourXMarker
      Set MessageCounter to 0 ;Ensuring your menu is seen
    Endif
       ;Add anything that needs to be re-initialized




  Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
    ;Ensuring your menu is seen
    If (MessageTimer > 0) || (MessageCounter > 0)
    ;Centralizing your menu decisions
      Set Choice to GetButtonPressed
    Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
      If (Choice > -1)
      if (MessageCounter < 30)
        Return
        set Choice to GetButtonPressed
      Endif
        if (Choice == -1)
      If (MenuMode 1001 == 0)
          if (MenuMode 1001 == 0)
        If (MenuMode 1004) || (MenuMode 1005) || (MenuMode 1006) ||
            if (MenuMode 1004 == 0) && (MenuMode 1005 == 0) && (MenuMode 1006 == 0) &&
          (MenuMode 1010) || (MenuMode 1011) || (MenuMode 1013) ||
              (MenuMode 1010 == 0) && (MenuMode 1011 == 0) && (MenuMode 1013 == 0) &&
          (MenuMode 1015) || (MenuMode 1016) || (MenuMode 1017) ||
              (MenuMode 1015 == 0) && (MenuMode 1016 == 0) && (MenuMode 1017 == 0) &&
          (MenuMode 1018) || (MenuMode 1019) || (MenuMode 1020) ||
              (MenuMode 1018 == 0) && (MenuMode 1019 == 0) && (MenuMode 1020 == 0) &&
          (MenuMode 1021) || (MenuMode 1024) || (MenuMode 1038) ||
              (MenuMode 1021 == 0) && (MenuMode 1024 == 0) && (MenuMode 1038 == 0) &&
          (MenuMode 1039) || (MenuMode 1044) || (MenuMode 1045) ||
              (MenuMode 1039 == 0) && (MenuMode 1044 == 0) && (MenuMode 1045 == 0) &&
          (MenuMode 1046) || (MenuMode 1047) || (MenuMode 1057)
              (MenuMode 1046 == 0) && (MenuMode 1047 == 0) && (MenuMode 1057 == 0)
          Return
              set MessageCounter to (MessageCounter + 1)
        Else
            endif
          Set MessageTimer to (MessageTimer - GetSecondsPassed)
           else ;MenuMode 1001
          Set MessageCounter to (MessageCounter - 1)
            set MessageCounter to 0
           Return
          endif
        Endif
         else ;Choice > -1
      Else ;MenuMode 1001
          set MessageCounter to 0
         Set MessageTimer to 1
         endif
        Set MessageCounter to 45
       else ;Display menu again
         Return
        set Choosing to -(Choosing)
       Endif
        set MessageCounter to 0
    Else ;Display menu again
        message "Trying menu again..."
      Message "Trying menu again..."
       endif
       Set Choosing to -(Choosing)
      Return
    Endif




  Elseif (Choosing == -1) ;Display your menu
    Elseif (Choosing == -1) ;Display your menu
    Set ExitButton to # ;1 in this example
      Set ExitButton to 1 ;Running menus in both GameMode and MenuMode
    Messagebox "What would you like to do?" "First Option" ... "Exit Menu"
      Messagebox "What would you like to do?" "First Option" "Exit Menu"
    Set Choosing to 1
      Set Choosing to 1
    Set Choice to GetButtonPressed
      Set Choice to -1
     Return
     Elseif (Choosing == 1) ;Catch the player's decision
      If (Choice == 0) ;First Option
        ;run your code for the first decision
      Elseif (Choice == 1) ;Exit Menu
        ;run your code for the second descision
        Set Choosing to 0 ;to finish up
      Endif


  Elseif (Choosing == 1) ;Catch the player's decision
    ;Allowing the player to set any number
     Elseif (Choice == 0) ;First Option
    short NumNewIngsDefault
      ;run your code for the first decision
    elseif (Choosing == -2)
      Set Choosing to 0 ;to finish up
          set ExitButton to -2 ;Running menus in both GameMode and MenuMode
    Elseif (Choice == 1) ;Second Option
          messagebox "Set the default number of essences to be created.
      ;run your code for the second descision
                    (Currently %g)", NumNewIngsDefault,
      Set Choosing to 0 ;to finish up
                            "About 10 fewer (-12 to -8)"
                            "About 5 fewer (-7 to -3)"
                            "Default to that amount -2"
                            "Default to that amount -1"
                            "Default to that amount"
                            "Default to that amount +1"
                            "Default to that amount +2"
                            "About 5 more (+3 to +7)"
                            "About 10 more (+8 to +12)"
                            "Return to previous menu"
          set Choosing to 2
          set Choice to -1
     elseif (Choosing == 2)
          if (Choice == 0) ;10 fewer
            set NumNewIngsDefault to (NumNewIngsDefault - 10)
            set Choosing to -2
          elseif (Choice == 1) ;5 fewer
            set NumNewIngsDefault to (NumNewIngsDefault - 5)
            set Choosing to -2
          elseif (Choice == 7) ;5 more
            set NumNewIngsDefault to (NumNewIngsDefault + 5)
            set Choosing to -2
          elseif (Choice == 8) ;10 more
            set NumNewIngsDefault to (NumNewIngsDefault + 10)
            set Choosing to -2
          elseif (Choice == 2) ;-2
            set NumNewIngsDefault to (NumNewIngsDefault - 2)
            set Choosing to -1
          elseif (Choice == 3) ;-1
            set NumNewIngsDefault to (NumNewIngsDefault - 1)
            set Choosing to -1
          elseif (Choice == 4) ;Cancel
            set Choosing to -1
          elseif (Choice == 5) ;+1
            set NumNewIngsDefault to (NumNewIngsDefault + 1)
            set Choosing to -1
          elseif (Choice == 6) ;+2
            set NumNewIngsDefault to (NumNewIngsDefault + 2)
            set Choosing to -1
          elseif (Choice == 9) ;Return to previous menu
            set Choosing to -1
          endif
     Endif
     Endif
  Elseif (Choosing == -2)
...
   Endif
   Endif
End</pre>
End</pre>
[[Category: Scripting Tutorials]]
[[Category: Scripting Tutorials]]
Anonymous user