Difference between revisions of "Adding an Options Menu"
Further categorised variables into global/specific, added "Utilising Your Variables" section, proofed and edited
imported>Cipscis m (Proofed and edited, added paragraph about variable names) |
imported>Cipscis (Further categorised variables into global/specific, added "Utilising Your Variables" section, proofed and edited) |
||
Line 3: | Line 3: | ||
<p>I'm assuming that anybody reading this is familiar enough with the GECK that I can ignore things like how to make a new quest, and can instead concentrate on the scripting side of things.</p> | <p>I'm assuming that anybody reading this is familiar enough with the GECK that I can ignore things like how to make a new quest, and can instead concentrate on the scripting side of things.</p> | ||
<h1> | <h1>Setting Up Your Plugin To Use An Options Menu</h1> | ||
<h2>Introduction</h2> | <h2>Introduction</h2> | ||
<p>Creating an Options Menu | <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> | |||
<ul> | <ul> | ||
<li> | <li> | ||
Analogue | Analogue/Digital | ||
<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> | <li> | ||
Global/Specific | |||
<ul> | |||
<li> | |||
Global - Settings that affect the game in general | |||
</li> | |||
<li> | |||
Specific - Settings that are specific to a certain object | |||
</li> | |||
</ul> | |||
</li> | </li> | ||
</ul> | </ul> | ||
<p>Each of these | <p>Each of these categories can utilise a slightly different menu structure, although they can all be incorporated into the same Options Menu.</p> | ||
<h2>Declaring | <h2>Declaring Your Variables</h2> | ||
<p>The first step in making these settings editable is to define them in a "Variable Reservoir | <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> | ||
<pre>ScriptName ExampleVariableReservoirSCRIPT | <pre>ScriptName ExampleVariableReservoirSCRIPT | ||
; | ; ============================================== | ||
; | ; Global Settings | ||
short | |||
short | short sGlobalDigitalSetting ; Default 1 - On | ||
; =============================================== | short sGlobalAnalogueSetting1 ; Default 3 | ||
ref rGlobalAnalogueSetting2 ; Default ExampleRef | |||
; ============================================== | |||
; ============================================== | |||
; Specific Settings | |||
; | ; Item1 | ||
short sItem1DigitalSetting ; Default 0 - Off | |||
short | short sItem1AnalogueSetting ; Default 5 | ||
short | |||
; | ; ============================================== | ||
</pre> | </pre> | ||
Line 42: | Line 66: | ||
<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> | ||
<h2>Initialising | <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> | ||
<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, 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> | ||
Line 48: | Line 74: | ||
<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 ExampleVariableReservoirSCRIPT:</p> | ||
<pre>set ExampleVariableReservoirQuest. | <pre>set ExampleVariableReservoirQuest.sGlobalDigitalSetting to 1 ; On | ||
set ExampleVariableReservoirQuest. | set ExampleVariableReservoirQuest.sGlobalAnalogueSetting1 to 3 | ||
set ExampleVariableReservoirQuest.rGlobalAnalogueSetting2 to ExampleRef | |||
set ExampleVariableReservoirQuest. | set ExampleVariableReservoirQuest.sItem1DigitalSetting to 0 ; Off | ||
set ExampleVariableReservoirQuest. | set ExampleVariableReservoirQuest.sItem1AnalogueSetting to 5 | ||
</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, 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> | ||
Line 71: | Line 99: | ||
<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 ExampleVariableReservoirQuest 1" to initialise our settings to their default values.</p> | ||
<h2>Utilising Your Variables</h2> | |||
<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> | |||
<h3>Analogue Settings</h3> | |||
<p>Associating the value of analogue settings with features depends entirely on the type of feature. For example, it might consist of several "if"/"elseif" statements like so:</p> | |||
<pre>if sGlobalAnalogueSetting1 == 0 | |||
; Do it this way | |||
elseif sGlobalAnalogueSetting1 == 1 | |||
; Do it that way | |||
else | |||
; Do it another way | |||
endif | |||
</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> | |||
<pre>ExampleVariableReservoirQuest.rGlobalAnalogueSetting2.KillActor ExampleVariableReservoirQuest.rGlobalAnalogueSetting2 ExampleVariableReservoirQuest.sGlobalAnalogueSetting1 | |||
</pre> | |||
<h3>Digital Settings</h3> | |||
<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> | |||
<pre>if ExampleVariableReservoirQuest.sGlobalDigitalSetting | |||
; 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>Keep in mind that this is not the only way in which the value of a digital setting can be tied to a feature. For example, digital settings can also be used as parameters for certain functions to change a small part of the function.</p> | |||
<h2>Still to Come</h2> | <h2>Still to Come</h2> | ||
<ul> | <ul> | ||
<li> | <li> | ||
Navigating The Options Menu | Navigating The Options Menu |