Category:Stage Functions

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Stage Functions refer to the use of Quest Stages as functions - repeatable series of commands that can be called at will.

How to Create and Use Stage Functions[edit | edit source]

Stage functions are created by checking "Allow repeated stages" in the Quest menu of a Global Script, and adding Stages to the Quest with Quest Stage result scripts that will be used as your functions. It is important to remember that result scripts cannot declare variables and do not use Begin/End blocks. This means that all the variables you will be using must be declared as a part of your Global Script. In general, it is advised that you declare special input and output variables solely for your functions, and change them before calling your stage function.

Calling a stage function is as simple as setting the stage, namely the SetStage command. By checking "Allow repeated stages", you can call functions whenever and as often as you like, even several times a frame. You are limited only by the framerate hit that heavy scripting (with or without functions) can cause.

Example[edit | edit source]

Assume we have a Quest called Wiki, with a Script attached called WikiStageFunctionExample. This script has two variables, Joe and Bob. This Quest has a Stage 10 like this:

set Wiki.Joe to ( Wiki.Bob * Wiki.Bob )
set Wiki.Bob to ( Wiki.Joe - 32 )

Obviously this is an extremely simple function that likely could just be repeated in your code whenever necessary, but there are plenty of functions (such as trigonometry functions) that require a lot of code that you do not want in your script every time you need them. Now, you could have your Global Script look something like this:

scn WikiStageFunctionExample

short Joe
short Bob

Begin GameMode

if ( Joe > Bob + 17 )
  setStage Wiki 10
  return
else
  set Bob to ( Bob - 5 )
  setStage Wiki 10
endif

set Bob to Joe
setStage Wiki 10

End

Notice that the stage function can be used multiple times, and will run when called, that is, the code could be expanded to read like this:

scn WikiStageFunctionExample

short Joe
short Bob

Begin GameMode

if ( Joe > Bob + 17 )
  set Joe to ( Bob * Bob )
  set Bob to ( Joe - 32 )
  return
else
  set Bob to ( Bob - 5 )
  set Joe to ( Bob * Bob )
  set Bob to ( Joe - 32 )
endif

set Bob to Joe
set Joe to ( Bob * Bob )
set Bob to ( Joe - 32 )

End

And this will all execute in a single frame. For another, more in-depth example, see the original article.

Stage Function Repository[edit | edit source]

This is a collection of functions you may use in your scripts which you may find useful. They were written based on a Quest called "Wiki" as above. Remember that the variables used by these functions must be declared in your Global Script. A list of these variables will be included with the code of the functions themselves.

For a complete quest+function layout already done, see the original Stage function repository, which attaches all of its functions to a single quest, "f", and already has the variables declared in the Quest's script.

Pages in category "Stage Functions"

The following 4 pages are in this category, out of 4 total.