• If you have a mod, tool or prefab, please use the Resources section. Click Mods at the top of the forums.

XPATH - Detect and Avoid Duplicates?

zztong

Hunter
Say you want to define something like a custom block with a name of "xyzTestBlock". Is there a way to determine if something with that name already exists, and then avoid declaring it again?

That is, don't do the following if it already exists:

<append xpath="/items">
<item name="xyzTestBlock" category="test">
<property name="Tags" value="fruit,vegetable"/>
<property name="Weight" value="12"/>
</item>
</append>




The web suggests lots of options (that don't seem very obvious) but I've no idea which XPATH we're using.

Oddly enough, I find myself wanting C Preprocessor Commands for conditional compilation.

 
Say you want to define something like a custom block with a name of "xyzTestBlock". Is there a way to determine if something with that name already exists, and then avoid declaring it again?

That is, don't do the following if it already exists:

<append xpath="/items">
<item name="xyzTestBlock" category="test">
<property name="Tags" value="fruit,vegetable"/>
<property name="Weight" value="12"/>
</item>
</append>




The web suggests lots of options (that don't seem very obvious) but I've no idea which XPATH we're using.

Oddly enough, I find myself wanting C Preprocessor Commands for conditional compilation.
Using https://code.visualstudio.com/ would be the best way to view syntax errors or potential dupes. Visual studio has some excellent plugins that allow automatic dupe detection.

 
Using https://code.visualstudio.com/ would be the best way to view syntax errors or potential dupes. Visual studio has some excellent plugins that allow automatic dupe detection.


Thanks. I was hoping for something within XPath so that I could keep the game from complaining about duplicates if a player happened to install two modlets that happen to declare identical blocks. That is, something in XPath kind of like the old C Preprocessor declarations, where you could say "if X is not defined then define X this way."

 
Thanks. I was hoping for something within XPath so that I could keep the game from complaining about duplicates if a player happened to install two modlets that happen to declare identical blocks. That is, something in XPath kind of like the old C Preprocessor declarations, where you could say "if X is not defined then define X this way."


There are no conditional commands supported by 7D2D.

The only thing I would suggest, is to first remove the other version block you're adding, then add your own version. Unfortunately that will result in a yellow warning if the block doesn't exist.

Now, what I'd really like to see is some way for modders to temporarily disable the yellow warnings, and do so within the XML itself. But I don't know if that will ever happen.

 
Back
Top