Sequence State System

Building a sequence state system is an absolute must for keeping in game sequences manageable.  A sequence is usually a scripted event that the player is not in control of.  It could be a full screen animation or an in game event.   Having this type of system allows you to start or end a sequence at any moment.

For example, at one point in the demo level an alert is sounded.  A red light flashes and Ammut and Tatenen ask each other what it is about.  After deciding they are not sure they begin to walk toward the bridge while the scene fades out and Ammut excitingly shouts “Alllarrrrmmm!!”.    The player is not in control and this is considered a scripted sequence. Another sequence is when we first see Ammut the camera shakes (with sound effects) and Ammut says he should get to the engine room.

Much of a sequence can be handled through XML.  The XML file will dictate the order that events in the sequence happen and it will also contain the dialogue for that sequence.
Here is a simple XML sequence.

			Use hand on Ammuts bed
			I'll just take a quick nap.
			start the nap...fade out...wait a few seconds!
			End the nap and fade back in
			Ahhh, much better.

In this sequence the player clicked Ammut’s bed with the Hand icon.  Ammut first says he will take a nap and then there are two actions.  The First action starts the nap (the camera fades out) and the second ends the nap(the camera fades back in).  These could easily be combined into one action but I wanted to show how you can have any number of actions.  Ammut then says he feels better.

The custom XML editor has a list of available characters for the specific scene to choose from so there is no need to worry about spelling errors and such.

The code handling the sequence consists of a sequence controller which keeps a dictionary (.net hashtable like array) of all the sequences that need their own script file.  If a sequence is simple enough, it can solely exist in the XML, if the sequence needs more complicated behavior it gets its own sequence script file.

The controller script has a lot to it but here is the method where the specific sequence is run.  The sequence name is a string because it comes from the XML file.

IEnumerator SequenceCoRoutine (string seq, int stateInput)
 currentSequence = seq;

 _sequenceRunning = true;

 yield return StartCoroutine(CheckForNoActions(seq));

 if (containsAction)
 yield return StartCoroutine(sequenceDictionary[seq].PerformSequence(stateInput));

 _sequenceRunning = false;

If the sequence contains no actions there is a method that will display the dialogue from the XML.  If there are actions, that sequences script file is run.

The sequence script file inherits from an abstract class that contains a startsequence method and endsequence method.  Dialogue from the XML is automatically spoken, and any specific action gets its own method that will be called and yielded to.  After all the actions and dialogue are done the endsequence method is run and the sequence ends.

Hopefully this will get you going on building a sequence state system.  If you’d like more details i’d be happy to post more about the system i’m using!

This entry was posted in DevBlog. Bookmark the permalink.

8 Responses to Sequence State System

Leave a Reply

Your email address will not be published. Required fields are marked *