Monday, March 2, 2015

Introducing how events are written: Hello world!

NOTE: technical post meant for whoever is interested on how the game events works.

I think I never explained how events for the game are written (other than saying they're written in XML)

So I'll start make some post where I show you some simple event and I'll explain what's it means.
So let's see the programmer basic, the hello world example.
We start by creating a new .xml file and put it in the events directory of the game. We call the f

ile MyFirstEvent.xml
and in the file we write:

<Events>
   <Event Name="hello_world">
      <SetText>Hello world</SetText>
   </Event>
</Events>

What all this mean?

<Events> is our root, all event defined in this file will be inside it.

<Event> is the definition of an Event and must contain in his attribute a Name. Having a name is necessary for the event to be referenced by the game or by other events.

Finally inside the event we have a <SetText>, I already said something about event step. Well this is the most basic one.
When the game see this event step, the given text is displayed to the user and the game will wait until the player click continue to go to the next event step.
Not all the event steps wait for the user input for example the <SetTitle> event step will be executed and will continue immediately to the next event step.

So for example we can do this:

<Events>
   <Event Name="hello_world">
      <SetTitle>My first event</SetTitle>
      <SetText>Hello world</SetText>
   </Event>
</Events>

When the event fire the title (the big text on the screen, you can see it in the figure on the bottom) will be setted to My first event and immediately the SetText will be fired setting the event text to hello world.

In order to play the event there's stilll one thing to do. The game doesn't know which event should be playable so you have to tell him.
For that you have to create an activity.
The game work in weeks, every week you decide what to do for the next, then all the event planned are played.
Activities are what the player can do during the week. For example things like: work at bar, rest, take a walk are all valid activities.
For our example we need to create a new activity (at the moment I can't say where you will have to write the activity bit since it'll change in the future.)
The activity is written like this:

     <Activity>
        <Name>Hello world activity</Name>
        <Duration>1</Duration>
        <EventReference>
            <DirectReference>
                <Path>Events/MyFirstEvent.xml</Path>
                <Name>hello_world</Name>
            </DirectReference>
        </EventReference>
    </Activity>

Let's see all the bits:

<Name>  This is the display name the user will see for that activity.
<Duration> How much in days the event is long. The maximum is 7. Note that things like 0.5 are valid numbers. (But atm all the basic events are 1 days long)
<EventReference> Is what event the activity will play. As you can see it contains a <DirectReference> that is an element you can use inside events too that contain the relative path of the file containing the event and the name of the event.

After adding your activity you will see it in game, you can select it and play it.
The result are shown here:


Note that the screen are going to change and are just for demostrative purpose

No comments:

Post a Comment