I can't figure out where I'm wrong.

Started by alexiltabaccaio, October 13, 2019, 03:34:40 AM

Previous topic - Next topic

alexiltabaccaio

Hi guys. I'm creating a patch, and I need to make sure that TableBasicProsthetic has to be unlocked through BasicProsthetics technology.
Yet I can't make it work. Sorry, I've been writing in xml for a few days.
If you could help me you would be the best.

that's where I got stuck.

             <li Class="PatchOperationAdd">
               <xpath>Defs/ThingDef[defName="TableBasicProsthetic"]researchPrerequisites</xpath>
                                          <value>
                    <researchPrerequisites>BasicProsthetics</researchPrerequisites>      
                 </value>      
                            </li>


Hjkma

Well, the patch is just wrong. Firstly, this xpath will not lead anywhere, this is a syntax error:
<xpath>Defs/ThingDef[defName = "TableBasicProsthetic"]researchPrerequisites</xpath>
It was necessary either to add / before "researchPrerequisites", or to remove this word.

Also, see if the thingDef itself contains researchPrerequisites or not. If it contains, then the operation must be changed to "PatchOperationReplace" and add / before "researchPrerequisites" in xpath. If not, then the word "researchPrerequisites" should be removed in xpath.

alexiltabaccaio

Hi. Thanks for the quick response! I have verified that the thingDef does not contain researchPrerequisites. That's why I didn't use the replace.
I also tried to remove researchPrerequisites in xpath. But it doesn't work anyway.

Hjkma

Post the full ThingDef and the patch. Then everything will become clear.

alexiltabaccaio

Here we are

This is the basic prosthetics workbench:

<ThingDef ParentName="BenchBase">
      <defName>TableBasicProsthetic</defName>
      <label>basic prosthetics workbench</label>
      <thingClass>Building_WorkTable</thingClass>
      <description>A workbench equipped for production of very simple prostheses.</description>
      <graphicData>
         <texPath>Things/Building/Production/TableBasicProsthetics</texPath>
         <graphicClass>Graphic_Multi</graphicClass>
         <shaderType>CutoutComplex</shaderType>
         <drawSize>(2.33,1.5)</drawSize>
       <damageData>
         <cornerTL>Damage/Corner</cornerTL>
         <cornerTR>Damage/Corner</cornerTR>
         <cornerBL>Damage/Corner</cornerBL>
         <cornerBR>Damage/Corner</cornerBR>
         </damageData>
      </graphicData>
      <stuffCategories>
         <li>Metallic</li>
         <li>Woody</li>
         <li>Stony</li>
      </stuffCategories>
      <costStuffCount>80</costStuffCount>
      <costList>
         <Steel>35</Steel>
      </costList>
      <altitudeLayer>Building</altitudeLayer>
      <statBases>
         <WorkToBuild>700</WorkToBuild>
         <MaxHitPoints>120</MaxHitPoints>
         <Flammability>1.0</Flammability>
         <Cleanliness>-2</Cleanliness>
      </statBases>
      <size>(2,1)</size>
      <comps>
         <li Class="CompProperties_AffectedByFacilities">
            <linkableFacilities>
               <li>ToolCabinet</li>
            </linkableFacilities>
         </li>
      </comps>
      <designationCategory>Production</designationCategory>
      <passability>PassThroughOnly</passability>
      <pathCost>60</pathCost>
      <hasInteractionCell>True</hasInteractionCell>
      <interactionCellOffset>(0,0,-1)</interactionCellOffset>
      <surfaceType>Item</surfaceType>
      <recipes>
         <li>CreatePegLeg</li>
         <li>CreateSteelArm</li>
         <li>CreateHookHand</li>
         <li>CreateEyePatch</li>
         <li>CreateEarBandage</li>
         <li>CreateDenture</li>
         <li>CreateWoodenFoot</li>
      </recipes>
      <inspectorTabs>
         <li>ITab_Bills</li>
      </inspectorTabs>
      <building>
         <spawnedConceptLearnOpportunity>BillsTab</spawnedConceptLearnOpportunity>
      </building>
      <placeWorkers>
         <li>PlaceWorker_ShowFacilitiesConnections</li>
      </placeWorkers>
   </ThingDef>
   
</Defs>



This is the research project where i want to put the workbench:

<ResearchProjectDef>
      <defName>BasicProsthetics</defName>
      <label>Basic prosthetics</label>
      <description>Understanding the shape of a leg and combining that knowledge with basic woodworking, you can now craft peg legs and other basic prostheses.</description>
      <baseCost>600</baseCost>
      <techLevel>Neolithic</techLevel>
      <tags>
         <li>ClassicStart</li>
      </tags>
      <tab>EPOE</tab>
      <researchViewX>0</researchViewX>
      <researchViewY>1.5</researchViewY>
   </ResearchProjectDef>



And this is the patch:

<?xml version="1.0" encoding="utf-8" ?>
<Patch>
   <Operation Class="PatchOperationFindMod">
      <mods>
         <li>Expanded Prosthetics and Organ Engineering</li>
      </mods>
      <match Class="PatchOperationSequence">
         <success>Always</success>
            <operations>
         
      <!--Change Tab>-->

      <!--BasicProsthetics-->

             <li Class="PatchOperationReplace">
               <xpath>Defs/ResearchProjectDef[defName="BasicProsthetics"]/tab</xpath>
                 <value>
                   <tab>AiT_tab_Prosthetics</tab>
                 </value>
            </li>

      <!--Prosthetics-->

             <li Class="PatchOperationReplace">
               <xpath>Defs/ResearchProjectDef[defName="Prosthetics"]/tab</xpath>
                 <value>
                   <tab>AiT_tab_Prosthetics</tab>
                 </value>
            </li>

      <!--Bionics-->

             <li Class="PatchOperationReplace">
               <xpath>Defs/ResearchProjectDef[defName="Bionics"]/tab</xpath>
                 <value>
                   <tab>AiT_tab_Prosthetics</tab>
                 </value>
            </li>

      <!--SurrogateOrgans-->

             <li Class="PatchOperationReplace">
               <xpath>Defs/ResearchProjectDef[defName="SurrogateOrgans"]/tab</xpath>
                 <value>
                   <tab>AiT_tab_Prosthetics</tab>
                 </value>
            </li>

      <!--RibReplacements-->

             <li Class="PatchOperationReplace">
               <xpath>Defs/ResearchProjectDef[defName="RibReplacements"]/tab</xpath>
                 <value>
                   <tab>AiT_tab_Prosthetics</tab>
                 </value>
            </li>

      <!--AdvancedBionics-->

             <li Class="PatchOperationReplace">
               <xpath>Defs/ResearchProjectDef[defName="AdvancedBionics"]/tab</xpath>
                 <value>
                   <tab>AiT_tab_Prosthetics</tab>
                 </value>
            </li>

      <!--SyntheticOrgans-->

             <li Class="PatchOperationReplace">
               <xpath>Defs/ResearchProjectDef[defName="SyntheticOrgans"]/tab</xpath>
                 <value>
                   <tab>AiT_tab_Prosthetics</tab>
                 </value>
            </li>

      <!--BrainSurgery-->

             <li Class="PatchOperationReplace">
               <xpath>Defs/ResearchProjectDef[defName="BrainSurgery"]/tab</xpath>
                 <value>
                   <tab>AiT_tab_Prosthetics</tab>
                 </value>
            </li>

      <!--END Change Tab-->

      <!--Empty Old Tab Removed-->

             <li Class="PatchOperationRemove">
               <xpath>Defs/ResearchTabDef[defName="EPOE"]</xpath>
            </li>

        <!--Empty Basic prosthetics Fix-->

             <li Class="PatchOperationAdd">
               <xpath>Defs/ThingDef[defName="TableBasicProsthetic"]/researchPrerequisites</xpath>
                      <value>
                    <researchPrerequisites>BasicProsthetics</researchPrerequisites>      
                 </value>      
                </li>

         </operations>      
      </match>
   </Operation>
</Patch>


Hjkma

This is how it should be.
<li Class="PatchOperationAdd">
<xpath>Defs/ThingDef[defName="TableBasicProsthetic"]</xpath>
<value>
<researchPrerequisites>BasicProsthetics</researchPrerequisites>     
</value>     
</li>

alexiltabaccaio

#6
Nope. It doesn't work. :(

Now I have this error

RimWorld 1.0.2408 rev747
Verse.Log:Message(String, Boolean)
RimWorld.VersionControl:LogVersionNumber()
Verse.Root:CheckGlobalInit()
Verse.Root:Start()
Verse.Root_Entry:Start()

Exception parsing <researchPrerequisites>BasicProsthetics</researchPrerequisites> to type System.Collections.Generic.List`1[Verse.ResearchProjectDef]: System.ArgumentException: Exception parsing System.Collections.Generic.List`1[Verse.ResearchProjectDef] from "BasicProsthetics" ---> System.ArgumentException: Trying to parse to unknown data type List`1. Content is 'BasicProsthetics'.
  at Verse.ParseHelper.FromString (System.String str, System.Type itemType) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Verse.ParseHelper.FromString (System.String str, System.Type itemType) [0x00000] in <filename unknown>:0
  at Verse.ParseHelper.FromString[List`1] (System.String str) [0x00000] in <filename unknown>:0
  at Verse.DirectXmlToObject.ObjectFromXml[List`1] (System.Xml.XmlNode xmlRoot, Boolean doPostLoad) [0x00000] in <filename unknown>:0
Verse.Log:Error(String, Boolean)
Verse.DirectXmlToObject:ObjectFromXml(XmlNode, Boolean)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[])
Verse.DirectXmlToObject:ObjectFromXml(XmlNode, Boolean)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[])
Verse.DirectXmlLoader:DefFromNode(XmlNode, LoadableXmlAsset)
Verse.LoadedModManager:ParseAndProcessXML(XmlDocument, Dictionary`2)
Verse.LoadedModManager:LoadAllActiveMods()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.Root:<Start>m__1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.LongEventHandler:<UpdateCurrentAsynchronousEvent>m__1()

Hjkma

Oh, try wrapping <li> around:
<li Class="PatchOperationAdd">
<xpath>Defs/ThingDef[defName="TableBasicProsthetic"]</xpath>
<value>
<researchPrerequisites><li>BasicProsthetics</li></researchPrerequisites>     
</value>     
</li>

LWM

#8
Try this: (Hjkma already got this, but thought I'd share the rest of my comments anyway)
<li Class="PatchOperationAdd">
<xpath>/Defs/ThingDef[defName="TableBasicProsthetic"]</xpath>
<value>
<researchPrerequisites><li>BasicProsthetics</li></researchPrerequisites>
</value>     
</li>


For what it's worth, I did a test last year-ish, and starting with "/Defs" is about 1-3% faster than "Defs" - you can see what I did (I showed my work, teacher!) in the xpath thread.

Also for what it's worth, if someone else adds a tech requirement to the bench, you'll step on each others' toes.  There's a way around that: breaking the operation into two steps (if there isn't researchPrerequisites, add that, and then add <li>yourTech</li> to researchPrerequisites), but if you don't care about that scenario.....that's pretty reasonable ;)

--LWM

alexiltabaccaio

#9
oh guys, it works!!! i love you. <3

at this point I have another question. how can I create a condition to add researchPrerequisites only if it is not there?


alexiltabaccaio

Thanks again, everybody. See you at the steam workshop.  8)