Xpath Help - Why can't I just replace a single value under <statBases>?

Started by Comrade Ryan, August 08, 2022, 05:57:57 PM

Previous topic - Next topic

Comrade Ryan

Hello everyone, need some beginner help with Xpath patching.

I'm trying to edit the nutritional value of Hay. Seems like it should be pretty straight forward - I just need to edit the <Nutrition> element. Here's the <statBases> for Hay:

    <statBases>
      <MarketValue>0.3</MarketValue>
      <Mass>0.014</Mass>
      <Flammability>1.5</Flammability>
  <Nutrition>0.05</Nutrition>
    </statBases>


So I did this:

<Operation Class="PatchOperationReplace">
<xpath>Defs/ThingDef[defName="Hay"]/statBases</xpath>
<value>
<statBases>
<Nutrition>0.15</Nutrition>
</statBases>
</value>
</Operation>


I thought it was working (nutrition was increased), but then I realized that my code had effectively removed the <MarketValue>, <Mass>, and <Flammability> statBases.

So I tried to be more specific with this:

<Operation Class="PatchOperationReplace">
<xpath>Defs/ThingDef[defName="Hay"]/statBases/Nutrition</xpath>
<value>
<Nutrition>0.15</Nutrition>
</value>
</Operation>


However, when I launch the game with that patch operation, I get this error:

Patch operation Verse.PatchOperationReplace(Defs/ThingDef[defName="Hay"]/statBases/Nutrition) failed
file: E:\Games\Steam\steamapps\common\RimWorld\Mods\TestMod 1.3.1\Patches\Plant_Changes.xml


Clearly I'm doing something wrong, but what is it? Can I not edit a sub-value of the <statBases> element? Do I need to include <MarketValue>, <Mass>, and <Flammability> in my replace operation, even if the values aren't being modified? (I have tested doing so, and it works, but I feel like that's not the "proper" way of patching.)

Any pointers would be greatly appreciated. Thank you for your time!





Comrade Ryan

Unsurprisingly, it's my fault.

I can't replace <Nutrition> because the base game doesn't have that tag as part of <statBases> for hay. Apparently the XML file I was looking at was already modified. Whoops!

I think this can be considered closed.