Strange behaviour when patching ResearchProjectDef

Started by Stormknight, April 14, 2018, 11:25:21 AM

Previous topic - Next topic

Stormknight

I'm trying to make several changes to the tech tree for a mod I'm working on and would like to use xpath patching so that I have as much compatibility as possible with other mods.

I feel like I must have missed something though, as it's behaving weirdly.

Consider the following patch code, that successfully adds Smithing as a prerequisite of Electricity:
<Operation Class="PatchOperationAdd">
<xpath>*/ResearchProjectDef[defName = "Electricity"]</xpath>
<value>
    <prerequisites>
      <li>Smithing</li>
    </prerequisites>
</value>
</Operation>


Now compare that to the following patch code I am trying to change the displayed name for Electricity in the tech tree:
<Operation Class="PatchOperationReplace">
<xpath>*/ResearchProjectDef[defName = "Electricity"]</xpath>
<value>
<label>Power</label>
</value>
</Operation>


The first chunk of code is successful, however when the second piece of code is added, it causes the whole Electricity entry to vanish from the research. In fact, it seems to cause the whole Electricity node to vanish, as having the REPLACE patch happening prior to the ADD patch causes the game to throw an error for the ADD action.

Does anyone out there know if it's possible to use patching and xpaths to change the values of ResearchDefs?

Mehni

/Defs/ResearchProjectDef[defName = "Electricity"]selects the entire node for Electricity. Your patch replaces the entire node instead of just the label.

/Defs/ResearchProjectDef[defName = "Electricity"]/label might be more what you're looking for.

Stormknight

Thank you Mehni,

Whilst I've used XML a fair amount before, I've not really touched xpaths and this really caught me out.

For reference, for anyone else looking to do this, the following works just fine:

<Patch>
<Operation Class="PatchOperationReplace">
<xpath>*/ResearchProjectDef[defName = "Electricity"]/label</xpath>
<value>
<label>Power</label>
</value>
</Operation>
</Patch>