Check if object exists, before change elements ...

Started by jabbamonkey, December 28, 2018, 06:31:21 PM

Previous topic - Next topic

jabbamonkey

I was about to package up my mod, and upload it ... but then I decided to test the mod without any other mods installed (because my mod also modifies textures in other mods).  I got some errors. It looks like the xpathing to change other mod elements is causing a problem when the other mod doesn't exist.

So, I am getting the following error...
Quote[Jabbamonkey's Graphic Overhaul] Patch operation Verse.PatchOperationSequence(count=25, lastFailedOperation=Verse.PatchOperationReplace(*/ThingDef[defName = "HookHand"]/graphicData/texPath)) failed
file: C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\JabbamonkeysGraphics\Patches\MedPatches.xml

And, below is the xpath where the error is coming from (note: this code works fine when the other mod is installed) ...

<li Class="patchOperationReplace">
<xpath>*/ThingDef[defName = "EyePatch"]/graphicData/texPath</xpath>
<value>[/quote]
<texPath>Things/Item/BodyPart/EyePatch</texPath>
</value>
</li>


As mentioned, this item is located in another mod. So, before xpathing, I need to either ...
a.) Check to see if the mod exists
b.) Check and see if the object exists (I prefer this, because they may change the elements in their mod)

Can someone tell me how to do this?

Razuhl

You can define a static result for patch operations. For example "<success>Always</success>" would prevent the message from popping up even if the mod is missing.

You can declare a PatchOperationConditional that executes either it's match or nomatch patchoperation as a follow up.