Skip to content

03. Basic template for opening sentences

sergiodinapoli edited this page Sep 11, 2021 · 1 revision

The following may be used as a basic template for opening sentences:

<Operation Class="PatchOperationReplace">
<xpath>/Defs/InteractionDef[defName = "ChitChat"]/logRulesInitiator/rulesStrings</xpath>
<value>
<rulesStrings>
<li>r_logentry(tag=Weather)->What a nice sunny day!</li>
<li>r_logentry(tag=FineFood)->I had a fine meal.</li>
</rulesStrings>
</value>
</Operation>

Let's examine its main elements:

a) <Operation Class="PatchOperationReplace">
It's the outermost tag, enclosing our social interaction. It refers to the Patch operation (it's a Rimworld internal feature).
A "Patch" is a direct replacement of a vanilla code part.

b) <xpath>/Defs/InteractionDef[defName = "ChitChat"]/logRulesInitiator/rulesStrings</xpath>
Here you specify which vanilla code part you wish to replace. In our case, we're replacing the ChitChat vanilla section with our custom-made content. This section is in the Interactions_Social.xml vanilla file, where there is an InteractionDef whose defName is ChitChat. Specifically, we're replacing whatever is included in the <rulesString> section.

If you wish, you can replace other parts of Interactions_Social.xml vanilla file (or other similar files) - you just have to specify the right path.

c) <value> and <rulesStrings>
Notice you have to specifiy <rulesStrings> both in the <xpath> and here.
Also, <rulesStrings> encloses all the <li> elements, i.e. all the lines of dialogue.

d) <li>r_logentry(tag=Weather)->What a nice sunny day!</li>
This is one of the actual lines of dialogue. Each line must:

  • start with <li> and end with </li>
  • have r_logentry-> just after <li>
    IMPORTANT: if you write r_logentry- and forget the >, the game will crash. Typos in general might be fatal so it's very important to make all the efforts to avoid them.

In this simple example, the program will randomly select one of the two lines and use it to start a dialogue.

d.1) (tag=Weather)
This is a key mechanism. It means the code will look up the Interactions.xml file (i.e. the reactions file) to search for an InteractionDef whose <defName> element matches "Weather". If it finds one, then it will be used as a reaction to our current social interaction. In our example, the first line will lead to an answer about weather, whereas the second line will lead to an answer about food.

IMPORTANT: you cannot use any space between the brackets. Resist the temptation to write (tag = Weather), or there will be bugs or worse.

Notice SpeakUp already contains basic patched content, so you might just expand the content inside the available PatchOperations by adding extra <li> lines - but you could also include new patch operations. I believe it's much safer to patch separate sections - for instance, I believe it's certain doom if you include two ChitChat patches in the same XML document, targeting the same vanilla sections.