Global Scripts

Revision as of 19:02, 9 May 2006 by imported>DragoonWraith (How do I make a global script? moved to Global Script)

Overview

If you're used to scripting in The Elder Scrolls III: Morrowind, you may be familiar with a concept known as "global scripts". In Morrowind, the way to run a global script — at least if you have the Tribunal or Bloodmoon expansions, or if you have the Morrowind Game of the Year Edition — is to create your script as normal, then specify it is a Start Script in the Construction Set.

In Oblivion, however, all scripts must be attached to objects of some kind. This, of course, presents a problem: how can you create an object which is always persistent in memory and always running its script? The answer, of course, is by creating a quest, then defining your script as a quest script.


What is a global script?

A global script is a script that needs to be running all the time in order to perform advanced scripting techniques. The actual uses for this vary a great deal, but reasons include: alterations of the locations of objects above and beyond the Havok physics engine; dynamic placement of creatures and objects; and modifications of NPCs on a grand scale (for instance, making every single NPC in the game burst into flames...).

Global scripts are designed to be running immediately from the very start of the game. This is distinct from other kinds of quest scripts which are triggered and only executed as the quest is in play.


Should I use a global script?

If you have to ask, then the answer is a very emphatic no!

Global scripts are inefficient and are not the recommended solution to most problems. If you find yourself considering using a global script, try to see if you can find some way to reduce the scope of your script somewhat — e.g., if your script only affects Actors inside a certain inn, you could easily get away with a script attached to an Activator instead, then place that Activator inside each cell of that inn.

Global scripts, by their very nature, must run all the time — unless they're actually performing calculations every single time your screen updates, this means that you're wasting many "ticks" of your computer's processor, which could be better spent drawing the beautiful game environment of Oblivion!


Step by Step Process:

Create a Quest

Before you can write your script, you need to create a quest to attach a script to. This is done by selecting "Character"->"Quests" from the menu at the top of the Construction Set. Once you are presented with the Quests dialog, move over to the white list on the left-hand side of the box. Under the "Editor ID" column button, right-click and choose "New" to create a new Quest. You are prompted for a name for your quest. Type in a good name and click OK.

After you have a quest ready, move over to the "Script" selection box, and click the button marked "..." in order to open the Script Editor.

Create your Script

This is a simple matter of programming. Refer to the Scripting category for all of the necessary information. You will also want to define float fQuestDelayTime inside your script. Set it to a low value (e.g., set fQuestDelayTime to 0.001) in order to have your script process every frame.

Once you have finished the meat of your script, go to the toolbar of the Script Editor dialog and select "Quest" from the Script Type drop-down list. You are ready to assign the script to the quest! Close the Script Editor now, and save your script if it prompts you. Be sure to correct any errors if they come up.

Sample Global Script Format

scriptname YourScriptNameGoesHere

;If this variable is defined, we can custom-tune how fast Oblivion
; will process this Quest script.  If you have a global script that
; needs precision, it is important to define this.
float fQuestDelayTime

;Any other script variables you'll need go here.
;***SCRIPT VARIABLES***


begin GameMode
    ;Conditions which should prevent this script from running go here.
    ; Use the "if ( condition )" command and then the "return" command.
    ;***CANCEL CONDITIONS***
    
    ;This specifies that we want this script to process every millisecond.
    ; Since no computer can run Oblivion at 1000 frames per second, this
    ; means that you want it to execute once every frame (usually quite a
    ; bit longer than 1 millisecond).
    ;Change this value as necessary to change the precision of your
    ; script.  Bear in mind that the fastest it can run is once per frame.
    set fQuestDelayTime to 0.001
    
    ;The actual meat of your script goes here.
    ;***SCRIPT CONTENTS***

end GameMode

Assign your Script to the Quest

Now that you are finished your script, the script can be attached to the quest. Simply select your new script from the "Script" dropdown list in the Quest dialog, and choose "OK" in the far bottom right corner of the Quest dialog.

Congratulations! You now have a global script.