Game reading contents of <!--Comments-->

Started by Deimos Rast, September 04, 2016, 02:42:24 PM

Previous topic - Next topic

Deimos Rast

Mod edit: this thread was moved from the Mods discussion forum. The summary is that 2 comments in series in XML seems to throw an error when it "shouldn't".




Is there a reason the game is reading the contents of comments (or even sees them at all)? I'll freely admit I'm not the saviest with coding, but I was always under the impression when you commented something out, it prevented the program from reading it. Completely (with minor exceptions). Yet on more than one occasion, I have found that to not be the case with RimWorld.
I kept getting "Duplicated XML node name #comment in this XML block" errors, but thought that couldn't be the issue (screenshot one). However, when I went to the Hediff referenced in the error, Feral_ArmorPiercing, and deleted the two commented out Hediff lines (screenshot two), the error disappeared.
Is that working as intended?

And yes, I know the joke.
Patient: "Doctor, my arm hurts when I bend it this way."
Doctor: "Then don't bend it that way."
But respectfully, that's missing the point.

http://imgur.com/hkdWJ6H
http://imgur.com/mUbPILw
#StopPluginAbuse

Master Bucketsmith

The defname might be in use elsewhere in your mod.
If you want, you could share what you have and someone else (like me) could glance over it.

theubie

The XML parser that Tynan wrote/uses does indeed read commented out lines like the rest.  It seems to throw it into the def you see referenced rather than throw it away completely. 

Moral of the story:  Don't use more than 1 comment in your XML.  (Learned that just the hard way just like you did)

kaptain_kavern

#3
That's strange. I mean you seems to know things better than I am, I merely fiddle with XML modding, but I use to sometimes heavily comments my mods code and never have problems because of commented code.  Unless I commented all the files content or forget to add a space between <!-- or --> tags and texts in comment (like in the title of that thread).

Plus in Core folders some files have several comments in them

Master Bucketsmith

Yeah I never have issues with having more than one commented section.

theubie

How to reproduce:

1 - Download my Core Driller mod.
2 - Launch game.
3 - Turn on Dev mode if it isn't already.
4 - Activate my mod.
5 - Close game.
6 - Open the Buildings_Production_CoreDriller.xml file in my mod's defs.
7 - Make the following change:

<?xml version="1.0" encoding="utf-8" ?>
<ThingDefs>

  <ThingDef ParentName="BuildingBase">
    <defName>CoreDrill</defName>
<ThingClass>Building_WorkTable</ThingClass>
    <label>core drill</label>
    <description>A ultra deep-crust drilling rig for extracting minerals from deep under the surface.</description>
    <size>(3,3)</size>
    <altitudeLayer>Building</altitudeLayer>
    <passability>PassThroughOnly</passability>
    <pathCost>70</pathCost>
    <fillPercent>0.5</fillPercent>
    <!-- <interactionCellOffset>(0,0,-1)</interactionCellOffset> -->
    <!-- <hasInteractionCell>true</hasInteractionCell> -->
    <designationCategory>Production</designationCategory>
    <rotatable>true</rotatable>
    <costList>
      <Steel>2000</Steel>
      <Component>10</Component>
  <Plasteel>400</Plasteel>
    </costList>
    <researchPrerequisites>
      <li>DeepDrilling</li>
    </researchPrerequisites>
    <statBases>
      <MaxHitPoints>140</MaxHitPoints>
      <WorkToMake>5000</WorkToMake>
      <Flammability>1.0</Flammability>
      <Beauty>-25</Beauty>
    </statBases>
    <comps>
      <li Class="CompProperties_Power">
        <compClass>CompPowerTrader</compClass>
        <startElectricalFires>false</startElectricalFires>
        <basePowerConsumption>2500</basePowerConsumption>
      </li>
      <li Class="CompProperties_Flickable"/>
      <li Class="CompProperties_Breakdownable"/>
    </comps>
    <graphicData>
      <graphicClass>Graphic_Single</graphicClass>
      <texPath>Things/Building/Production/DeepDrill</texPath>
      <drawSize>(4,4)</drawSize>
      <drawRotated>false</drawRotated>
    </graphicData>
<recipes>
      <li>MiningDeepSteel</li>
  <li>MiningDeepPlasteel</li>
  <li>MiningDeepUranium</li>
  <li>MiningDeepSilver</li>
  <li>MiningDeepGold</li>
  <li>MiningDeepJade</li>
    </recipes>
    <inspectorTabs>
      <li>ITab_Bills</li>
    </inspectorTabs>
  </ThingDef>
 
</ThingDefs>

8 - Save that file.
9 - Launch game again.
10 -


This only happens if you comment the lines individually.  If you comment the lines together in one comment, it doesn't happen.

Master Bucketsmith

The end section of an XML file of one of my mods:
<!-- ========================= Weapons and projectiles ======================== -->
<!-- ========================= Spotlight weapon ======================== -->
<ThingDef Name="Gun_Spotlight">
<defName>Gun_Spotlight</defName>
<category>Item</category>
<thingClass>ThingWithComps</thingClass>
<equipmentType>Primary</equipmentType>
<tickerType>Normal</tickerType>
<comps>
<li>
<compClass>CompEquippable</compClass>
</li>
</comps>
<label>spotlight lamp</label>
<techLevel>Industrial</techLevel>
<destroyOnDrop>True</destroyOnDrop>
<menuHidden>True</menuHidden>
<tradeability>Never</tradeability>
<statBases>
<MarketValue>1500</MarketValue>
<AccuracyTouch>1.00</AccuracyTouch>
<AccuracyShort>1.00</AccuracyShort>
<AccuracyMedium>1.00</AccuracyMedium>
<AccuracyLong>1.00</AccuracyLong>
<RangedWeapon_Cooldown>0</RangedWeapon_Cooldown>
</statBases>
<weaponTags>
<li>TurretGun</li>
</weaponTags>
<verbs>
<li>
<!--<verbClass>Verb_LaunchProjectile</verbClass> original, trying verb_shoot -->
<verbClass>Verb_Shoot</verbClass>
<hasStandardCommand>true</hasStandardCommand>
<!--<projectileDef>Bullet_Spotlight</projectileDef>-->
<warmupTicks>0</warmupTicks>
<range>50</range>
<minRange>0.5</minRange>
</li>
</verbs>
</ThingDef>
<!-- ========================= Spotlight projectile ======================== -->
<!--<ThingDef Name="Bullet_Spotlight">
<defName>Bullet_Spotlight</defName>
<category>Projectile</category>
<label>spotlight round</label>
<tickerType>Normal</tickerType>
<altitudeLayer>Projectile</altitudeLayer>
<thingClass>SpotlightMod.ProjectileBlank</thingClass>
<graphicData>
<texPath>Things/Projectile/SpotlightInv</texPath>
<graphicClass>Graphic_Single</graphicClass>
<shaderType>Transparent</shaderType>
</graphicData>
<neverMultiSelect>True</neverMultiSelect>
<useHitPoints>False</useHitPoints>
<projectile>
<damageDef>Stun</damageDef>
<DamageAmountBase>0</DamageAmountBase>
<Speed>1000</Speed>
</projectile>
</ThingDef>-->
</ThingDefs>

Having no issues with "duplicate XML node name #comment".

theubie

In none of the def blocks do you have more than one comment.

Master Bucketsmith

Quote from: theubie on September 06, 2016, 05:31:56 AM
In none of the def blocks do you have more than one comment.
This bug is specific to inside a specific Def? Thought you meant in the entire XML file.
Anyways, take a look at the <verbs> list item. There's two comments there.

theubie

I know for sure if you have more than one node directly under ThingDef it will throw it.  Li doesn't appear to throw it.

Deimos Rast

Quote from: theubie on September 06, 2016, 05:39:15 AM
stuff
any idea why? Thanks for the responses, glad it's not just me.
I mean, it's not the end of the world to work around it, but it just strikes me as very atypical behavior. Plus, I make a lot of comments. I'm pretty new to modding (or more specifically modding mods ;D), and I frequently comment out lines instead of outright delete them, and thus generate a lot of spurious comments, that I might want for later reference, etc etc. You know the type.
I hate deleting those. :-\
#StopPluginAbuse

Master Bucketsmith

Tiny workaround would be flipping the order of two lines in the XML file so you don't get two comments under one another.
Since XML doesn't care in what order the tags are, right?

theubie

Yup.  Doesn't care what order.  Also, just put all the lines you want to comment together and make one comment around them.


<!-- <stuff>1</stuff>
       <otherstuff>true</otherstuff
       <thing>abc</thing> -->

Rearden

just had this issue. kinda an odd issue. thanks for sharing

AngleWyrm

It seems the xml parser doesn't allow one comment to follow another comment.

So something like this throws an error:

    <!-- ========================= Weapons and projectiles ======================== -->
    <!-- ========================= Spotlight weapon ======================== -->
My 5-point rating system: Yay, Kay, Meh, Erm, Bleh