Adding an Options Menu

Revision as of 07:08, 24 December 2008 by imported>Cipscis (Proofed and edited, added paragraph about variable names)

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.

Adding an Options Menu

Introduction

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:

  • Analogue settings - Settings with many possible values
  • Digital settings - Settings with two possible values - on or off

Each of these settings utilises a slightly different menu structure, although they can both be incorporated into the same Options Menu.

Declaring Our Variables

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:

ScriptName ExampleVariableReservoirSCRIPT

; ===============================================
; Digital Settings
short sDigitalSetting1		; Default 1 - On
short sDigitalSetting2		; Default 0 - Off
; ===============================================

; ===============================================
; Analogue Settings
short sAnalogueSetting1	; Default 3
short sAnalogueSetting2	; 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.

Initialising Our 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.sDigitalSetting1 to 1
set ExampleVariableReservoirQuest.sDigitalSetting2 to 0

set ExampleVariableReservoirQuest.sAnalogueSetting1 to 3
set ExampleVariableReservoirQuest.sAnalogueSetting2 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.

Still to Come

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

See Also