Jump to content

XPATH - Detect and Avoid Duplicates?


zztong

Recommended Posts

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.

Link to comment
Share on other sites

  • 2 months later...
On 4/15/2023 at 10:42 PM, zztong said:

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.

Link to comment
Share on other sites

2 hours ago, Survivors vs Survivors said:

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."

 

 

Link to comment
Share on other sites

On 6/21/2023 at 9:17 PM, zztong said:

 

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...