Difference between revisions of "Adding an Options Menu"

2,020 bytes added ,  06:33, 26 December 2008
Re-wrote introduction and "Utilising Your Variables" sections to clarify categorisations
imported>Cipscis
(Further categorised variables into global/specific, added "Utilising Your Variables" section, proofed and edited)
imported>Cipscis
(Re-wrote introduction and "Utilising Your Variables" sections to clarify categorisations)
Line 9: Line 9:
<p>Creating an Options Menu is a good way to keep your plugin modular without having to make multiple plugin files available.  It allows the user to change settings in-game.</p>
<p>Creating an Options Menu is a good way to keep your plugin modular without having to make multiple plugin files available.  It allows the user to change settings in-game.</p>


<p>Settings can be categorised in two ways - Analogue/Digital and Global/Specific.</p>
<p>Depending on how each setting works, it will utilise a slightly different menu structure.  In order to make it clear which menu structure should be used for each setting, I'm going to sort them into four categories:</p>


<ul>
<ul>
<li>
<li>
Analogue/Digital
General Toggle Settings, or GTs.  GTs affect the game as a whole, and can be toggled on and off.  They have the simplest menu structure of all setting types, and can be toggled simply by clicking on their button in the main menu.
<ul>
<li>
Analogue - Settings that can take on many values
</li>
<li>
Digital - Settings that can take on two values - 1 and 0 (corresponding with on and off)
</li>
</ul>
</li>
</li>
<li>
General Select Settings, or GSs.  GSs affect the game as a whole, and have a range of values available to them.  Their menu structure consists of a button on the main menu, and a sub-menu in which the user can select a new value for them.  Note that these values can include an "off" value.
</li>
<li>
<li>
Global/Specific
Object-Specific Toggle Settings, or OTs.  OTs affect specific objects, and can be toggled on and off.  Usually, many different objects will have their own versions of each OT.  The menu structure used by OTs requires the user to select the appropriate object before toggling the OT by pressing the relevant button.
<ul>
</li>
<li>
 
Global - Settings that affect the game in general
<li>
</li>
Object-Specific Select Settings, or OSs.  OSs affect specific objects, and have a range of values available to them.  OSs have the most complex menu structure of any setting, in that the user must first select the relevant object, then the setting, and then choose a new value for the setting.
<li>
Specific - Settings that are specific to a certain object
</li>
</ul>
</li>
</li>
</ul>
</ul>


<p>Each of these categories can utilise a slightly different menu structure, although they can all be incorporated into the same Options Menu.</p>
<p>Although each of these categories utilises a slightly different menu structure, they can all be incorporated into the same Options Menu.</p>


<h2>Declaring Your Variables</h2>
<h2>Declaring Your Variables</h2>


<p>The first step in making these settings editable is to define them in a "Variable Reservoir", or "VR" Quest Script.  A VR script is a script that contains no Begin/End blocks, but consists entirely of variable declarations.  This example VR script, which is attached to the "Start Game Enabled" quest "ExampleVariableReservoirQuest", will be used in this tutorial:</p>
<p>The first step in making these settings editable is to define them in a "Variable Reservoir", or "VR" Quest Script.  A VR script is a script that contains no Begin/End blocks, but consists entirely of variable declarations.  This example VR script, which is attached to the "Start Game Enabled" quest "ExampleVRQuest", will be used in this tutorial:</p>


<pre>ScriptName ExampleVariableReservoirSCRIPT
<pre>ScriptName ExampleVRSCRIPT


; ==============================================
; ==============================================
; Global Settings
; General Settings


short sGlobalDigitalSetting ; Default 1 - On
short sGT1 ; Default 1 - On
short sGlobalAnalogueSetting1 ; Default 3
short sGS1 ; Default 3
ref rGlobalAnalogueSetting2 ; Default ExampleRef
ref rGS2 ; Default ExampleRef
; ==============================================
; ==============================================


; ==============================================
; ==============================================
; Specific Settings
; Object-Specific Settings


; Item1
; Item1
short sItem1DigitalSetting ; Default 0 - Off
short sItem1OT1 ; Default 0 - Off
short sItem1AnalogueSetting ; Default 5
short sItem1OS1 ; Default 5


; ==============================================
; ==============================================
Line 66: Line 59:
<p>Keep in mind that your variables should be named according to their function.  The variable names I have used here were chosen to illustrate the type of setting they are used for, and are not practical.</p>
<p>Keep in mind that your variables should be named according to their function.  The variable names I have used here were chosen to illustrate the type of setting they are used for, and are not practical.</p>


<p>You should name your variables according to the setting that they affect, and the object that they are associated to (for Specific Variables).</p>
<p>You should name your variables according to the setting that they affect, and the object that they are associated to (for OTs and OSs).</p>


<h2>Initialising Your Variables</h2>
<h2>Initialising Your Variables</h2>


<p>To initialise these variables, we are going to add a result script to Stage 1 of our VR quest.  A result script is different from regular scripts in that it can't declare any variables of its own, and it doesn't contain any Begin/End blocks.  Instead, a quest result script will run once when its quest reaches the stage that it is attached to, provided that the conditions assigned to it evaluate to true.</p>
<p>To initialise these variables to their default values, we are going to add a result script to Stage 1 of our VR quest.  A result script is different from regular scripts in that it can't declare any variables of its own, and it doesn't contain any Begin/End blocks.  Instead, a quest result script will run once when its quest reaches the stage that it is attached to, provided that the conditions assigned to it evaluate to true.</p>


<p>This is the result script that would used to initialise the variables in ExampleVariableReservoirSCRIPT:</p>
<p>This is the result script that would used to initialise the variables in ExampleVRSCRIPT:</p>


<pre>set ExampleVariableReservoirQuest.sGlobalDigitalSetting to 1 ; On
<pre>set ExampleVRQuest.sGT1 to 1 ; On
set ExampleVariableReservoirQuest.sGlobalAnalogueSetting1 to 3
set ExampleVRQuest.sGS1 to 3
set ExampleVariableReservoirQuest.rGlobalAnalogueSetting2 to ExampleRef
set ExampleVRQuest.rGS2 to ExampleRef


set ExampleVariableReservoirQuest.sItem1DigitalSetting to 0 ; Off
set ExampleVRQuest.sItem1OT1 to 0 ; Off
set ExampleVariableReservoirQuest.sItem1AnalogueSetting to 5
set ExampleVRQuest.sItem1OS1 to 5
</pre>
</pre>


<p>Note that, even though variables initialise to 0, we have set sDigitalSetting2 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 ExampleVariableReservoirQuest 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 "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>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 ExampleVariableReservoirQuest 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>


<p>To do this, we will create another "Start Game Enabled" quest, this time in the interest of initialising our variables.  The quest script attached to ExampleInitQuest will look like this:</p>
<p>To do this, we will create another "Start Game Enabled" quest, this time in the interest of initialising our variables.  The quest script attached to ExampleInitQuest will look like this:</p>
Line 92: Line 85:
Begin GameMode
Begin GameMode


SetStage ExampleVariableReservoirQuest 1
SetStage ExampleVRQuest 1
StopQuest ExampleInitQuest
StopQuest ExampleInitQuest


Line 98: Line 91:
</pre>
</pre>


<p>As you can see, it will run only once - using "SetStage ExampleVariableReservoirQuest 1" to initialise our settings to their default values.</p>
<p>As you can see, it will run only once - using "SetStage ExampleVRQuest 1" to initialise our settings to their default values.</p>


<h2>Utilising Your Variables</h2>
<h2>Utilising Your Variables</h2>
Line 104: Line 97:
<p>At the moment, all our variables are doing is sitting in our VR quest.  If we make any changes to their values they won't affect the plugin in any way.</p>
<p>At the moment, all our variables are doing is sitting in our VR quest.  If we make any changes to their values they won't affect the plugin in any way.</p>


<p>Tying these variables to settings will always depend on just how the setting works, and is generally done differently depending on whether the setting is an Analogue setting or a Digital setting.</p>
<p>Tying these variables to settings will always depend on just how the setting works, and is generally done differently depending on the category that the setting belongs to.</p>


<h3>Analogue Settings</h3>
<h3>GTs</h3>


<p>Associating the value of analogue settings with features depends entirely on the type of featureFor example, it might consist of several "if"/"elseif" statements like so:</p>
<p>General Toggle settings are usually used to toggle features on and offTherefore, the most common way of linking GTs to their feature is to simply enclose the relevant code in an if statement:</p>


<pre>if sGlobalAnalogueSetting1 == 0
<pre>if ExampleVRQuest.sGT1
; Do it this way
; Function code goes here
elseif sGlobalAnalogueSetting1 == 1
; Do it that way
else
; Do it another way
endif
endif
</pre>
</pre>


<p>Analogue settings might also be used as parameters for functions like [[KillActor]], or they may point to persistent references in order to change the object that a certain feature affects:</p>
<p>As you can see, enclosing the relevant code in an if statement like the one above will cause the feature to be present if and only if ExampleVRQuest.sGT1 is not 0.  This will enable the feature to be toggled on and off by toggling ExampleVRQuest.sGT1 on and off.</p>


<pre>ExampleVariableReservoirQuest.rGlobalAnalogueSetting2.KillActor ExampleVariableReservoirQuest.rGlobalAnalogueSetting2 ExampleVariableReservoirQuest.sGlobalAnalogueSetting1
<p>For General Toggle settings, the relevant feature's code will usually be present in a single place - usually a quest script.  This means that only one section of code usually needs to be enclosed in an if statement.</p>
 
<h3>GSs</h3>
 
<p>General Select settings are usually used to change how a certain feature works.  They will usually be seen in calculations, or as parameters for certain functions.  For example:</p>
 
<pre>ExampleVRQuest.rGS2.KillActor ExampleVRQuest.rGS2 ExampleVRQuest.sGS1
</pre>
</pre>


<h3>Digital Settings</h3>
<p>In the above code, ExampleVRQuest.rGS2 controls which actor will be killed, and ExampleVRQuest.sGS1 controls which limb will be dismembered.  They can also be used to switch on/off certain aspects of the feature:</p>


<p>Associating the value of a digital setting with a certain feature is usually done by placing an "if" statement around the code that denotes the feature:</p>
<ul>
<li>
If ExampleVRQuest.sGS1 is set to -1, no limb will be dismembered
</li>
<li>
If ExampleVRQuest.rGS2 is set to point to a dummy reference (i.e. one the player will never encounter), no actor will be killed.
</li>
</ul>
 
<h3>OTs</h3>
 
<p>Object-Specific Toggle settings are usually used to toggle features on and off.  Therefore, the most common way of linking TTs to their feature is to simply enclose the relevant code in an if statement:</p>
 
<pre>if ExampleVRQuest.sItem1OT1
; Function code goes here
endif
</pre>
 
<p>As you can see, enclosing the relevant code in an if statement like the one above will cause the feature to be present if and only if ExampleVRQuest.sItem1OT1 is not 0.  This will enable the feature to be toggled on and off by toggling ExampleVRQuest.sItem1OT1 on and off.</p>
 
<p>For Object-Specific Toggle settings, the relevant feature's code will usually be present in a multiple places, as multiple objects will have their own copy of the feature.  This means that many sections of code usually need to be enclosed in the same if statement.</p>


<pre>if ExampleVariableReservoirQuest.sGlobalDigitalSetting
<h3>OSs</h3>
; Code that affects the associated feature goes here
endif</pre>


<p>Obviously, this "if" statement should enclose all code segments that affect the relevant feature</p>
<p>Object-Specific Select settings are usually used to change how a certain feature works.  They will usually be seen in calculations, or as parameters for certain functions.  For example:</p>
 
<pre>player.AddItem Item1 ExampleVRQuest.sItem1OS1
</pre>


<p>Keep in mind that this is not the only way in which the value of a digital setting can be tied to a featureFor example, digital settings can also be used as parameters for certain functions to change a small part of the function.</p>
<p>In the above code, ExampleVRQuest.sItem1OS1 controls how many of Item1 is added to the playerIf sItem1OS1 is set to 0, none will be given to the player, effectively switching the feature off.</p>


<h2>Still to Come</h2>
<h2>Still to Come</h2>
Anonymous user