User Tools

Site Tools


Sidebar

hpl2:tutorials:script:sequences

Scripting Sequences

A “Sequence” is a series of events. In Amnesia, a sequence will describe a chain of events that happen in your story! This is useful for any sort of long cutscene, or some sort of intro sequence.

The problem

Our first problem that we encounter when thinking about this is, how do we keep track of what part of the sequence we're on? Our second problem would be how to go about structuring it.

Keeping Track of What Part of the Sequence We're in

When we think about it, all we really need is a unique identifier that would denote each section of a sequence. With a unique identifier, and the availability of variables, we can quickly see that either an integer or string can be used. For example, for some intro sequence, I could use “introWakeup”, “introWalkToDoor”, “introOpenDoor”, “introSoilSelf” as unique identifiers to denote what part we're in. This is a user friendly way, but it's quite expensive in memory (compared to the other method). The other method we can utilize (and the one I will be using in this tutorial) is using integers. Like strings, we can store integers. The only real advantage is memory. Integers will not take up more space than a string of characters in memory, so if you're concious about that stuff, then great!

In addition to being low on memory, integers have some other advantages. For instance, if your sequence is 10 parts long, using an int will be able to tell us where we are, percentage wise. If we're at part 5 (in this example), then we know we are 50% done. This is useful for allowing the players to skip a sequence after a certain percentage of viewing (as in, the first part of an intro may be important to view, while the rest isn't).

Using integers also allows you to change what part of the sequence the player is in easily, and with minimal effort. For example, say the player triggered something that would omit a certain part of a sequence. Using ints, we can simply do part+=2, and this will skip to the part after the next.

Structuring it all

We do not want to go ahead and create a function for each part of a sequence, right? (well, unless you're a masochist) So we need to find a way to keep it all nice and tidy. Having timers, and the ability for a function to call itself, we can do this quite easily. What we can do is have one sole function that will be called repeatedly by itself to progress through the parts. We will use a switch statement to only show the current part of the sequence. Switch statements are quick and effecient ways to branch out code.

Digging into the Code

To start, get your hps file up and ready to edit. Once that is done, we will start by creating the “introSequence” function.

void introSequence(string &in asTimer)
{
}

Simple enough, now moving on. Remember our first requirement. We need a way to track the part of the sequence we're on. Let's use a local variable for this. (remember, I'm using integers, you can easily edit it to use strings)

void OnEnter()
{
     SetLocalVarInt("iIntroPart", 0); // Initialize the sequence to null
}

void OnStart()
{
     AddTimer("tmrIntro", 1.0f, "introSequence"); // Launch the introduction sequence 1 second in
}

void int

    
                    
                                    
hpl2/tutorials/script/sequences.txt · Last modified: 2011/07/29 21:28 by xiphirx