Tuesday, April 21, 2015

Introducing how event are written 4: References

As I said in the previous post, I would make a tutorial for using the references in event creation.

Okay, let's start with two simple events:

<Event Name="work_in_bar">
  <SetText>!$trainee worked at the bar.</SetText>
  <AddBody>Wear ++ Worked in bar</AddBody>
  <AddBody>Clean - Worked in bar</AddBody>
  <AddMind>Wear + Workd in bar</AddMind>
  <AddMoney>
    <Reason>Worked in bar</Reason>
    <Amount>[MinimumWage] * 1.2</Amount>
  </AddMoney>
</Event>

<Event Name="work_in_bar_2">
  <SetText>While working at the bar !$trainee fell. OUCHIE!</SetText>
  <AddBody>Wear + !$trainee fell down</AddBody>
  <AddBody>Wear ++ Worked in bar</AddBody>
  <AddBody>Clean - Worked in bar</AddBody>
  <AddMind>Wear + Workd in bar</AddMind>
  <AddMoney>
    <Reason>Worked in bar</Reason>
    <Amount>[MinimumWage] * 1.2</Amount>
  </AddMoney>
</Event>

Both events are about the slave working at the bar, but one event is slightly different from the other.
There's a part that it's identical in the two events, which is the "result" for working at the bar. The result is whathever the slave gained by working there, in this case money, fatigue and dirtiness.

Well, I don't know you but I don't like repetitions...
Well, I don't know you but I don't like repetitions...

Whops...
Anyway thanks to the cutting edge technology that are event reference we can rewrite the two event like this:


<Event Name="work_in_bar">
  <SetText>!$trainee worked at the bar.</SetText>
  <DirectReference>default_reward</DirectReference>
</Event>

<Event Name="work_in_bar_2">
  <SetText>While working at the bar !$trainee fell. OUCHIE!</SetText>
  <AddBody>Wear + !$trainee fell down</AddBody>
  <DirectReference>default_reward</DirectReference>
</Event>

<Event Name="default_reward">
  <AddBody>Wear ++ Worked in bar</AddBody>
  <AddBody>Clean - Worked in bar</AddBody>
  <AddMind>Wear + Workd in bar</AddMind>
  <AddMoney>
    <Reason>Worked in bar</Reason>
    <Amount>[MinimumWage] * 1.2</Amount>
  </AddMoney>
</Event>

So why is this better?

Well, now when I'll addd "work_in_bar_3" I just have to reference the "default_reward" event instead of copying it and pasting as I have done in the first example.

And speaking of copy & paste, look! Have you noticed the mistake I have done?

  <AddMind>Wear + Workd in bar</AddMind>

should be

  <AddMind>Wear + Worked in bar</AddMind>

Well, in the first example I made the mistake twice since I just copied paste the whole event.
For each copy paste I have now to correct the error. In this case (just a small spelling error) it might be fine. But think about more complex error or text that has been copied 5-6 times, the problem is harder to solve, you will start to miss some place, expecially if the text is copied past on different files.



The reference you have seen is valid only for events whitin the same file. For referencing an event in another file you use this:

<DirectReference>pathToYourFile;eventName</DirectReference>

for example

<DirectReference>Events/Common.xml;strip_all</DirectReference>

That reference is one you will see in the event file since it's an event that strips all the clothes of the slave.


I hope I've explained it in a compresible manner.
See you next tutorial!

No comments:

Post a Comment