Difference between revisions of "Adding an Options Menu"

From the Fallout3 GECK Wiki
Jump to navigation Jump to search
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>Adding an Options Menu</h1>
<h1>Setting Up Your Plugin To Use An Options Menu</h1>


<h2>Introduction</h2>
<h2>Introduction</h2>


<p>Creating an Options Menu for is a good way to keep your plugin Modular without having to make multiple plugin files available.  It allows the user to change two types of 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>
 
<ul>
<ul>
<li>
<li>
Analogue settings - Settings with many possible values
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>
Digital settings - Settings with two possible values - on or off
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 settings utilises a slightly different menu structure, although they can both be incorporated into the same Options Menu.</p>
<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 Our Variables</h2>
<h2>Declaring Your Variables</h2>


<p>The first step in making these settings editable is to define them in a "Variable Reservoir Quest Script" or "VR 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 "ExampleVariableReservoirQuest", will be used in this tutorial:</p>


<pre>ScriptName ExampleVariableReservoirSCRIPT
<pre>ScriptName ExampleVariableReservoirSCRIPT


; ===============================================
; ==============================================
; Digital Settings
; Global Settings
short sDigitalSetting1 ; Default 1 - On
 
short sDigitalSetting2 ; Default 0 - Off
short sGlobalDigitalSetting ; Default 1 - On
; ===============================================
short sGlobalAnalogueSetting1 ; Default 3
ref rGlobalAnalogueSetting2 ; Default ExampleRef
; ==============================================
 
; ==============================================
; Specific Settings


; ===============================================
; Item1
; Analogue Settings
short sItem1DigitalSetting ; Default 0 - Off
short sAnalogueSetting1 ; Default 3
short sItem1AnalogueSetting ; Default 5
short sAnalogueSetting2 ; Default 5
 
; ===============================================
; ==============================================
</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 Our Variables</h2>
<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.sDigitalSetting1 to 1
<pre>set ExampleVariableReservoirQuest.sGlobalDigitalSetting to 1 ; On
set ExampleVariableReservoirQuest.sDigitalSetting2 to 0
set ExampleVariableReservoirQuest.sGlobalAnalogueSetting1 to 3
set ExampleVariableReservoirQuest.rGlobalAnalogueSetting2 to ExampleRef


set ExampleVariableReservoirQuest.sAnalogueSetting1 to 3
set ExampleVariableReservoirQuest.sItem1DigitalSetting to 0 ; Off
set ExampleVariableReservoirQuest.sAnalogueSetting2 to 5</pre>
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>
Utilising Our Variables
</li>
<li>
<li>
Navigating The Options Menu
Navigating The Options Menu

Revision as of 23:08, 24 December 2008

This tutorial is a Work in Progress. If you have any feedback or suggestions, please leave a comment in the discussion page.

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.

Setting Up Your Plugin To Use An Options Menu

Introduction

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.

Settings can be categorised in two ways - Analogue/Digital and Global/Specific.

  • Analogue/Digital
    • Analogue - Settings that can take on many values
    • Digital - Settings that can take on two values - 1 and 0 (corresponding with on and off)
  • Global/Specific
    • Global - Settings that affect the game in general
    • Specific - Settings that are specific to a certain object

Each of these categories can utilise a slightly different menu structure, although they can all be incorporated into the same Options Menu.

Declaring Your Variables

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:

ScriptName ExampleVariableReservoirSCRIPT

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

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

; ==============================================
; Specific Settings

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

; ==============================================

Note that it consists entirely of variable declarations, and will never actually run. That means that these variables need some method of being initialised to their default values - at the moment they are all 0.

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.

You should name your variables according to the setting that they affect, and the object that they are associated to (for Specific Variables).

Initialising Your Variables

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.

This is the result script that would used to initialise the variables in ExampleVariableReservoirSCRIPT:

set ExampleVariableReservoirQuest.sGlobalDigitalSetting to 1 ; On
set ExampleVariableReservoirQuest.sGlobalAnalogueSetting1 to 3
set ExampleVariableReservoirQuest.rGlobalAnalogueSetting2 to ExampleRef

set ExampleVariableReservoirQuest.sItem1DigitalSetting to 0 ; Off
set ExampleVariableReservoirQuest.sItem1AnalogueSetting to 5

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.

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.

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:

ScriptName ExampleInitSCRIPT

Begin GameMode

	SetStage ExampleVariableReservoirQuest 1
	StopQuest ExampleInitQuest

End

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

Utilising Your Variables

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.

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.

Analogue Settings

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:

if sGlobalAnalogueSetting1 == 0
	; Do it this way
elseif sGlobalAnalogueSetting1 == 1
	; Do it that way
else
	; Do it another way
endif

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:

ExampleVariableReservoirQuest.rGlobalAnalogueSetting2.KillActor ExampleVariableReservoirQuest.rGlobalAnalogueSetting2 ExampleVariableReservoirQuest.sGlobalAnalogueSetting1

Digital Settings

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:

if ExampleVariableReservoirQuest.sGlobalDigitalSetting
	; Code that affects the associated feature goes here
endif

Obviously, this "if" statement should enclose all code segments that affect the relevant feature

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.

Still to Come

  • Navigating The Options Menu
  • Allowing User Access
  • Anything else that I think of

See Also