Sequences Revisited

I’d like to show a little more detail on the various types of sequence events.

I’m going to share some xml to demonstrate what happens in a sequence.

Here is a part of a sequence in the game.
First: Tatenen walks to coordinates -3299 x -182
Second: Ammut walks to coordinates -3299 x -244
Third: FadeIn the camera and take 1.5 seconds to do it.
Fourth: Wait 2 seconds while the fade takes place.

 <preDefinedAction type="NPCWalkToPoint" object="Tatenen" x="-3299" z="-182">Tatenen walks left</preDefinedAction>
 <preDefinedAction type="NPCWalkToPoint" object="Ammut" x="-3299" z="-244">Ammut Walks left</preDefinedAction>
 <preDefinedAction FadeIn="1.5">Fade back in</preDefinedAction>
 <preDefinedAction wait="2">wait for fade</preDefinedAction>
 <preDefinedAction type="WaitForNPCToMove" object="Ammut"></preDefinedAction>
 <speak spkChar="Ammut" spkType="bighead">What is the meaning of this?</speak>

To run this sequence I have a sequence controller script that will parse this information as coroutines so that we can “yield” to each line.
The NPCWalkToPoint runs code which looks like this (note* this is not the code directly. The real code is much more generic than this. But for demonstration I thought this would be more useful to a beginner to see it fully broken down.):

float x = float.Parse(node.Attributes["x"].Value);
float z = float.Parse(node.Attributes["z"].Value);
string NPCName = node.Attributes["object"].Value;
//send the npc name and coordinates to a method that makes that npc walk to the coordinates.
yield return StartCoroutine(Movement.NPCWalkToPointNoYield(new Vector2(x,z),NPCName));

The next event would be a FadeIn.

float time =  float.Parse(node.Attributes["FadeIn"].Value;
yield return StartCoroutine(ScreenFade.FadeIn(time));

The Wait event

float time = float.Parse(node.Attributes["wait"].Value);
yield return StartCoroutine(Timer.Wait(time));

Make sure the NPC has stopped moving and has reached its destination

string NPCName = node.Attributes["object"].Value;
yield return StartCoroutine(Movement.WaitForNPCToMove(NPCName));

Speak some dialogue!
What is the meaning of this?

string charName = node.Attributes["spkChar"].Value;
string spkType = node.Attributes["spkType"].Value;
string textToSpeak = node.InnerText;
yield return StartCoroutine(Speach.speak(charName,spkType,textToSpeak);

I have probably about 100 or so event types setup in this manner and I constantly am adding more. The idea is to make any events be scripted through the XML and not in code. The sequence controller will parse the xml and run specified methods that do all the work. You could make a very simple visual editor based on this method for scripting events.
Hopefully this gives you some ideas!

This entry was posted in DevBlog. Bookmark the permalink.

4 Responses to Sequences Revisited

  1. Sir Kill A Lot says:

    Hi, nice to see development if this game is going forward!

    Two notes:

    1. When parsing XML you should use the well defined XML schema datatypes and convert them from/to string using class XmlConvert, e.g.:
    float x = System.Xml.XmlConvert.ToSingle("123.45");

    2. If you want to use those Parse() methods it’s better to supply format provider to prevent potential problems on non-English systems:
    float x = Single.Parse("123.45", System.Globalization.CultureInfo.InvariantCulture);

    (Disclaimer: I don’t use/know Unity)

  2. Mike Pinto says:

    Thanks for the tips Sir Kill A Lot!

  3. Uwe says:

    Thanks for these posts and for sticking with the dev blog! I’m learning a lot from your approach.
    Once all systems are finished you should consider selling a 2D adventure kit on the asset store.
    Awesome work!

Leave a Reply

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