Difference between revisions of "Adding an Options Menu"

672 bytes removed ,  01:02, 18 January 2009
Restructured menu navigation to make it clearer; added "Defaults" button info
imported>Cipscis
(→‎Creating An Options Menu: Decided to work on the Menu section this time)
imported>Cipscis
(Restructured menu navigation to make it clearer; added "Defaults" button info)
Line 76: Line 76:
</pre>
</pre>


<p>Note that, even though variables initialise to 0 anyway, we have set sItem1OT1 to 0 in this result script.  This ensures that a "Set to Defaults" option can be included in the Options Menu that can set or reset all settings to their default values with a simple "SetStage ExampleVRQuest 1" command.</p>
<p>Note that, even though variables initialise to 0 anyway, we have set sItem1OT1 to 0 in this result script.  This ensures that a "Defaults" option can be included in the Options Menu that can set or reset all settings to their default values with a simple "SetStage ExampleVRQuest 1" command.</p>


<p>Of course, we need some way in which to run this result script initially - as it will not be run until our VR quest reaches Stage 1.  Attaching the result script to Stage 0 (which quests default to when they first start running) won't work, we need to actually use "SetStage ExampleVRQuest 1" somewhere.</p>
<p>Of course, we need some way in which to run this result script initially - as it will not be run until our VR quest reaches Stage 1.  Attaching the result script to Stage 0 (which quests default to when they first start running) won't work, we need to actually use "SetStage ExampleVRQuest 1" somewhere.</p>
Line 270: Line 270:
<p>Now that that's set up, all that's left is the actual Menu script, which will be attached to the token.</p>
<p>Now that that's set up, all that's left is the actual Menu script, which will be attached to the token.</p>


<h2>Creating the Options Menu</h2>
<h2>Creating the menu</h2>


<p>The main difference between a single-level menu and a multi-level menu is that the latter requires navigation - the script needs to remember the path that the player took to get to where they are.  Our script will achieve this by having a "sMenuLevel" variable to store the current level of navigation, and giving each level of navigation its own "sButton" variable.  That way, the script can remember which buttons the player pressed on each level of navigation.</p>
<p>The main difference between a single-level menu and a multi-level menu is that the latter requires navigation - the script needs to remember the path that the player took to get to where they are.  Our script will achieve this by having a "sMenuLevel" variable to store the current level of navigation, and giving each level of navigation its own "sButton" variable.  That way, the script can remember which buttons the player pressed on each level of navigation.</p>
Line 280: Line 280:
<li>Level 1 - Introduction Message->Main Menu</li>
<li>Level 1 - Introduction Message->Main Menu</li>
<li>Level 2 - Main Menu->Sub Menu</li>
<li>Level 2 - Main Menu->Sub Menu</li>
<li>Level 3 - Sub menu->Change Settings</li>
<li>Level 3 - Sub menu->Settings</li>
</ul>
</ul>


Line 291: Line 291:
; 1 - Introduction Message -> Main Menu
; 1 - Introduction Message -> Main Menu
; 2 - Main Menu -> Sub Menu
; 2 - Main Menu -> Sub Menu
; 3 - Sub Menu -> Change Settings
; 3 - Sub Menu -> Setting


; This GameMode block contains all of the ShowMessage framework
; This GameMode block contains all of the ShowMessage framework
Line 300: Line 300:
; =================================================
; =================================================
if sMenuLevel == 0 ; Show Introduction Message
if sMenuLevel == 0 ; Show Introduction Message
endif
endif
; =================================================
; /INITIALISATION --> INTRODUCTION MESSAGE
; =================================================




Line 311: Line 308:
; =================================================
; =================================================
if sMenuLevel == 1
if sMenuLevel == 1
endif
endif
; =================================================
; /INTRODUCTION MESSAGE --> MAIN MENU
; =================================================




Line 322: Line 316:
; =================================================
; =================================================
if sMenuLevel == 2
if sMenuLevel == 2
endif
endif
; =================================================
; /MAIN MENU --> SUB MENU
; =================================================




; =================================================
; =================================================
; SUB MENU --> CHANGE SETTING
; SUB MENU --> SETTING
; =================================================
; =================================================
if sMenuLevel == 3
if sMenuLevel == 3
endif
endif
; =================================================
; /SUB MENU --> CHANGE SETTING
; =================================================


End
End
Line 344: Line 332:
<p>As you can see, the GameMode block is now divided up into four different segments.  Which one runs will depend on the menu's current level of navigation.</p>
<p>As you can see, the GameMode block is now divided up into four different segments.  Which one runs will depend on the menu's current level of navigation.</p>


<p>The first section of the script runs when sMenuLevel == 0.  Because variables are initialised to 0, this section will run when the script first runs.  This section is also the simplest - all that happens in it is the introduction message is called, sMenuLevel is incremented, and sButton1 is intialised:</p>
<p>The first section of the script runs when sMenuLevel == 0.  Because variables are initialised to 0, this section will run when the script first runs.  This section is also the simplest - all that happens in it is the introduction message is called, sMenuLevel is incremented to 1, and sButton1 is intialised:</p>


<pre> ; =================================================
<pre> ; =================================================
Line 354: Line 342:
set sButton1 to -1
set sButton1 to -1
endif
endif
; =================================================
; /INITIALISATION --> INTRODUCTION MESSAGE
; =================================================
</pre>
</pre>


<p>If you're wondering why I've included an Introduction message before the Main Message, it's useful if you have conditions for the buttons in the Main Menu that have to be initialised before each time it's opened.  Usually, you'll use an OnAdd block in this script to do this.</p>
<p>If you're wondering why I've included an Introduction message before the Main Message, it's useful if you have conditions for the buttons in the Main Menu that have to be initialised before each time it's opened.  Usually, you'll use an OnAdd block in this script to initialise them.</p>


<p>Now, because we've set sMenuLevel to 1, the next section of the script is running.  In this section, we need to check when the player clicks the button to continue from the Introduction message into the Main Menu.  When this does happen, the script will call the Main Menu, increment sMenuLevel again, and initialise the next sButton variable - sButton2:</p>
<p>Now, because we've set sMenuLevel to 1, the next section of the script will run.  In this section, we need to check when the player clicks the button to continue from the Introduction message into the Main Menu.  When this happens, the script will call the Main Menu, increment sMenuLevel to 2, and initialise the next sButton variable - sButton2:</p>


<pre> ; =================================================
<pre> ; =================================================
Line 378: Line 363:
else ; Show the Main Menu
else ; Show the Main Menu


; mainMenu contains buttons corresponding to Sub Menus
; MainMenuMessage contains buttons corresponding to Sub Menus
ShowMessage mainMenu
ShowMessage MainMenuMessage
set sMenuLevel to 2
set sMenuLevel to 2
set sButton2 to -1
set sButton2 to -1
Line 386: Line 371:


endif
endif
; =================================================
; /INTRODUCTION MESSAGE --> MAIN MENU
; =================================================
</pre>
</pre>


<p>You may already have guessed what the next section consists of - it's a step up again in complexity.  Unlike the Introduction Message, the Main Menu contains multiple buttons.  That means that, in this section of the script, we need to check which button the player presses and update the Menu accordingly.</p>
<p>The next section is a step up again in complexity.  Unlike the Introduction Message, the Main Menu contains multiple buttons.  That means that, in this section of the script, we need to check which button the player presses and update the Menu accordingly.</p>
 
<p>There are three types of button in this Main Menu:</p>
 
<ul>
<li>Buttons that take the player to a Sub Menu</li>
<li>A "Defaults" button that sets all settings to their default values</li>
<li>A "Done" button that closes the menu</li>
</ul>


<p>If the player presses a button that takes them deeper into the menu, we'll need to call the appropriate message.  If, instead, the player presses the "Done" button, we'll need to remove the Menu Token in order to stop the script and therefore close the menu. We'll also need to increment sMenuLevel, and initialise the next sButton variable - sButton3:</p>
<p>If the player clicks on a Sub Menu button, we'll need to show the appropriate message, as well as increment sMenuLevel to 3 and set sButton3 to -1.  If they click the "Defaults" button, we'll need to set all settings to their default values (with "SetStage ExampleVRQuest 1", remember?), then show the Main Menu again and reset sButton2 to -1.  If the player clicks on the "Done" button, we'll remove the token from their inventory to close the menu.</p>


<pre> ; =================================================
<pre> ; =================================================
Line 410: Line 400:
elseif sButton2 == 0 ; Show the 1st Sub Menu
elseif sButton2 == 0 ; Show the 1st Sub Menu


ShowMessage subMenu1
ShowMessage SubMenu1Message


elseif sButton2 == 1 ; Show the 2nd Sub Menu
elseif sButton2 == 1 ; Show the 2nd Sub Menu


ShowMessage subMenu2
ShowMessage SubMenu2Message
 
elseif sButton2 == 2 ; "Defaults" button - reinitialise all settings
 
SetStage ExampleVRQuest 1
ShowMessage MainMenuMessage
set sButton2 to -1
Return


else ; "Done" button - close Options Menu
else ; "Done" button - close Options Menu
Line 424: Line 421:


set sMenuLevel to 3
set sMenuLevel to 3
set sButton3 to -1
set sButton3 to -1


endif
endif
; =================================================
; /MAIN MENU --> SUB MENU
; =================================================
</pre>
</pre>


<p>As you can see, this section is practically identical to the previous section.  The only differences are that there is a "Done" button and, depending on which button the player pressed, a different menu is shown.  We still use GetButtonPressed to check if a button has been pressed, and when one has we increment sMenuLevel and initialise the next sButton variable.</p>
<p>As you can see, this section has the same organisation as the previous section.  The only differences are that there are "Done" and "Defaults" buttons and, depending on which button the player pressed, a different menu is shown.  We still use [[GetButtonPressed]] to check if a button has been pressed, and when one has we increment sMenuLevel and initialise the next sButton variable.</p>


<p>The next section is the final section for this example script - it's where the actual settings are changed.  It differs from the previous level in that, when a button is pressed, we change a quest variable (remember them?) instead of showing a menu, and it has a "Back" button instead of a "Done" button.</p>
<p>The next section is the final section for this example script - it's where the actual settings are changed.  It differs from the previous level in that, when a button is pressed, we change a quest variable (remember them?) instead of showing a menu, and it has a "Back" button instead of a "Done" button.</p>


<p>There are two ways this can be sorted - by which setting was selected and by which sub-menu the player came through.  In this example, the script is sorted by which setting was selected.</p>
<p>There are two ways this section can be organised - by which setting was selected and by which sub-menu the player came through.  In this example, the script is sorted by which sub-menu the player came through.  The reason for this is that it is easier to visualise and can shorten the script a fair amount.</p>


<pre> ; =================================================
<pre> ; =================================================
; SUB MENU --> CHANGE SETTING
; SUB MENU --> SETTING
; =================================================
; =================================================
if sMenuLevel == 3
if sMenuLevel == 3
Line 452: Line 445:
Return ; None of the buttons have been pressed yet
Return ; None of the buttons have been pressed yet


elseif sButton3 == 0 ; The 1st setting was selected
elseif sButton2 == 0 ; The player came through the 1st Sub Menu
 
if sButton2 == 0 ; The player came through the 1st Sub Menu


if sButton3 == 0 ; The 1st setting was selected
set VariablesQuest.Variable1 to (VariablesQuest.Variable1 == 0)
set VariablesQuest.Variable1 to (VariablesQuest.Variable1 == 0)
 
elseif sButton3 == 1 ; The 2nd setting was selected
elseif sButton2 == 1 ; The player came through the 2nd Sub Menu
 
set VariablesQuest.Variable2 to (VariablesQuest.Variable2 == 0)
set VariablesQuest.Variable2 to (VariablesQuest.Variable2 == 0)
endif
endif
ShowMessage SubMenu1Message


elseif sButton3 == 1 ; The 2nd setting was selected
elseif sButton2 == 1 ; The player came through the 2nd Sub Menu
 
if sButton2 == 0 ; The player came through the 1st Sub Menu


if sButton3 == 0 ; The 1st setting was selected
set VariablesQuest.Variable3 to (VariablesQuest.Variable3 == 0)
set VariablesQuest.Variable3 to (VariablesQuest.Variable3 == 0)
 
elseif sButton3 == 1 ; The 2nd setting was selected
elseif sButton2 == 1 ; The player came through the 2nd Sub Menu
 
set VariablesQuest.Variable4 to (VariablesQuest.Variable4 == 0)
set VariablesQuest.Variable4 to (VariablesQuest.Variable4 == 0)
endif
endif
ShowMessage SubMenu2Message


else ; "Back" button was pressed
else ; "Back" button was pressed


set sMenuLevel to 1
ShowMessage MainMenuMessage
set sMenuLevel to 2
set sButton2 to -1
Return
Return


endif
endif


set sMenuLevel to 2
set sMenuLevel to 3
set sButton3 to -1


endif
endif
; =================================================
; /SUB MENU --> CHANGE SETTING
; =================================================
</pre>
</pre>


<p>As you can see, the highest level of "if" statements in this example checks which setting has been selected, and the next level of "if" statements checks which sub-menu the player has come through.  It would be perfectly acceptable to swap these two around if you'd like.</p>
<p>As you can see, the highest level of "if" statements in this example checks which Sub Menu the player came though, and the next level of "if" statements checks setting they just selected.  It would be perfectly acceptable to swap these two around if you'd like.</p>


<p>This method of making multi-level menus can be used to make menus with any number of levels that you'd like, although obviously the script will become more complicated at higher levels.  You should also remember that the structure that I've used in these examples is not set in stone by any means - you can, for example, change some variables straight from the main menu.</p>
<p>This method of making multi-level menus can be used to make menus with any number of levels that you'd like, although obviously the script will become more complicated at higher levels.  You should also remember that your menu doesn't have to function as an options menu.  It could be used for many other things - for example, determining which path the player will progress along in a quest.</p>


<p>Now that the script is finished, let's look at the whole thing in one piece!</p>
<p>Now that the script is finished, let's look at the whole thing in one piece!</p>
Line 503: Line 490:
; 1 - Introduction Message -> Main Menu
; 1 - Introduction Message -> Main Menu
; 2 - Main Menu -> Sub Menu
; 2 - Main Menu -> Sub Menu
; 3 - Sub Menu -> Change Settings
; 3 - Sub Menu -> Setting


short sButton1 ; sButton variable for the Introduction Message level
short sButton1 ; sButton variable for the Introduction Message level - Menu level 1
short sButton2 ; sButton variable for the Main Menu level
short sButton2 ; sButton variable for the Main Menu level - Menu level 2
short sButton3 ; sButton variable for the Sub Menu level
short sButton3 ; sButton variable for the Sub Menu level - Menu level 3


; This GameMode block contains all of the ShowMessage framework
; This GameMode block contains all of the ShowMessage framework
Line 520: Line 507:
set sButton1 to -1
set sButton1 to -1
endif
endif
; =================================================
; /INITIALISATION --> INTRODUCTION MESSAGE
; =================================================




Line 540: Line 524:
else ; Show the Main Menu
else ; Show the Main Menu


; mainMenu contains buttons corresponding to Sub Menus
; MainMenuMessage contains buttons corresponding to Sub Menus
ShowMessage mainMenu
ShowMessage MainMenuMessage
set sMenuLevel to 2
set sMenuLevel to 2
set sButton2 to -1
set sButton2 to -1
Line 548: Line 532:


endif
endif
; =================================================
; /INTRODUCTION MESSAGE --> MAIN MENU
; =================================================




Line 568: Line 549:
elseif sButton2 == 0 ; Show the 1st Sub Menu
elseif sButton2 == 0 ; Show the 1st Sub Menu


ShowMessage subMenu1
ShowMessage SubMenu1Message


elseif sButton2 == 1 ; Show the 2nd Sub Menu
elseif sButton2 == 1 ; Show the 2nd Sub Menu


ShowMessage subMenu2
ShowMessage SubMenu2Message
 
elseif sButton2 == 2 ; "Defaults" button - reinitialise all settings
 
SetStage ExampleVRQuest 1
ShowMessage MainMenuMessage
set sButton2 to -1
Return


else ; "Done" button - close Options Menu
else ; "Done" button - close Options Menu
Line 582: Line 570:


set sMenuLevel to 3
set sMenuLevel to 3
set sButton3 to -1
set sButton3 to -1


endif
endif
; =================================================
; /MAIN MENU --> SUB MENU
; =================================================




; =================================================
; =================================================
; SUB MENU --> CHANGE SETTING
; SUB MENU --> SETTING
; =================================================
; =================================================
if sMenuLevel == 3
if sMenuLevel == 3
Line 604: Line 588:
Return ; None of the buttons have been pressed yet
Return ; None of the buttons have been pressed yet


elseif sButton3 == 0 ; The 1st setting was selected
elseif sButton2 == 0 ; The player came through the 1st Sub Menu
 
if sButton2 == 0 ; The player came through the 1st Sub Menu


if sButton3 == 0 ; The 1st setting was selected
set VariablesQuest.Variable1 to (VariablesQuest.Variable1 == 0)
set VariablesQuest.Variable1 to (VariablesQuest.Variable1 == 0)
 
elseif sButton3 == 1 ; The 2nd setting was selected
elseif sButton2 == 1 ; The player came through the 2nd Sub Menu
 
set VariablesQuest.Variable2 to (VariablesQuest.Variable2 == 0)
set VariablesQuest.Variable2 to (VariablesQuest.Variable2 == 0)
endif
endif
ShowMessage SubMenu1Message


elseif sButton3 == 1 ; The 2nd setting was selected
elseif sButton2 == 1 ; The player came through the 2nd Sub Menu
 
if sButton2 == 0 ; The player came through the 1st Sub Menu


if sButton3 == 0 ; The 1st setting was selected
set VariablesQuest.Variable3 to (VariablesQuest.Variable3 == 0)
set VariablesQuest.Variable3 to (VariablesQuest.Variable3 == 0)
 
elseif sButton3 == 1 ; The 2nd setting was selected
elseif sButton2 == 1 ; The player came through the 2nd Sub Menu
 
set VariablesQuest.Variable4 to (VariablesQuest.Variable4 == 0)
set VariablesQuest.Variable4 to (VariablesQuest.Variable4 == 0)
endif
endif
ShowMessage SubMenu2Message


else ; "Back" button was pressed
else ; "Back" button was pressed


set sMenuLevel to 1
ShowMessage MainMenuMessage
set sMenuLevel to 2
set sButton2 to -1
Return
Return


endif
endif


set sMenuLevel to 2
set sMenuLevel to 3
set sButton3 to -1


endif
endif
; =================================================
; /SUB MENU --> CHANGE SETTING
; =================================================


End
End
Anonymous user