Jump to content

Creating Mod but xpath only partially works


CounterBalance

Recommended Posts

Something isn't working for me. I get my item to show up in the creator menu but not my crafting menu. I also sometimes get a red text error saying my xpath attribute isn't set.

Here is my items.xml

 

<configs>

 

<append xpath="/items">

 

<item name="resourceBasicString"> <!-- scrap material -->

<property name="CustomIcon" value="modGunBowPolymerString"/>

<property name="CustomIconTint" value="79826c"/> <!--Gray with a little green-->

<property name="HoldType" value="45"/>

<property name="Meshfile" value="#Other/Items?Misc/sackPrefab.prefab"/>

<property name="DropMeshfile" value="#Other/Items?Misc/sack_droppedPrefab.prefab"/>

<property name="Material" value="Mcloth"/>

<property name="Stacknumber" value="250"/> <!-- STK resource -->

<property name="RepairAmount" value="50"/>

<property name="FuelValue" value="1"/>

<property name="Weight" value="5"/> <property name="EconomicValue" value="6"/>

<property name="EconomicBundleSize" value="6"/>

<property name="Group" value="Resources"/>

<property name="CraftingIngredientExp" value="15"/>

<property name="CraftingIngredientTime" value="15"/>

 

</item> </append>

 

</configs>

 

Here is the receipes.xml

 

<configs>

 

<append xpath="/recipes">

<recipe name="resourceBasicString" count="1">

<ingredient name="resourceYuccaFibers" count="6"/>

</recipe>

 

</append>

 

</configs>

 

I tried without /configs and I get error and I tried with <modetitle></modtitle> from a comment I read somewhere saying it closes everything up but that didn't help. Also when I put the recipe directly into vanilla it works fine. Any ideas?

Link to comment
Share on other sites

The surrounding XML tags don't really matter, they're only there to make the entire file valid XML. Many people (myself included) use "configs" without issue.

 

That XML seems OK to me, but it's possible there's a typo that we both missed. It might help if you posted the text of the error here.

 

If you have any doubts about what you changed, you can open the command console using F1 and type "exportcurrentconfigs" (without quotes). It will put the current XML configuration files - including any modlet edits - into the save game directory, in a folder called "ConfigsDump". There will be auto-generated comments in the XML saying what has changed and what changed it.

 

Once you look at the modded XML files, it's usually pretty obvious what went wrong.

Link to comment
Share on other sites

Hi CounterBalance

 

In items.xml this part must not go together </item> </append>, </append> must go under </item>. 


This other part should also not go together <property name = "Weight" value = "5" /> <property name = "EconomicValue" value = "6" />. 

 

In recipes it should be like this:

 

<configs>
<append xpath = "/ recipes">
     <recipe name = "resourceBasicString" count = "1">
         <ingredient name = "resourceYuccaFibers" count = "6" />
     </recipe>
</append>
</configs>

 

You must always match the names to avoid any mistakes and make it quicker to identify them.
Hope that helps you.
Regards

Link to comment
Share on other sites

 

   Well before I start, I wanted to thank everyone who responded to my post so far now and in the future. I wasn't expecting anything so soon or really anyone at all, perhaps someone a few months from now when I had long given up and moved on or the problem was already solved. On top of that some really good responses. So overall this seems like a great community! So thank you!

 

 

10 hours ago, khzmusik said:

The surrounding XML tags don't really matter, they're only there to make the entire file valid XML. Many people (myself included) use "configs" without issue.

 

That XML seems OK to me, but it's possible there's a typo that we both missed. It might help if you posted the text of the error here.

 

If you have any doubts about what you changed, you can open the command console using F1 and type "exportcurrentconfigs" (without quotes). It will put the current XML configuration files - including any modlet edits - into the save game directory, in a folder called "ConfigsDump". There will be auto-generated comments in the XML saying what has changed and what changed it.

 

Once you look at the modded XML files, it's usually pretty obvious what went wrong.

 

 

   I didn't know about this. I followed the instructions. It seems the game does this automatically from the message it game me. I looked up the files and saw the recipes.xml and the items.xml.

     I saw all my append added to the file, but there were no additions and comments about my recipes append. The F1 had given me the error that my recipes mod had an xpath attribute missing and wasn't loaded to the game.

 

 

 

 

7 hours ago, convergent said:

In your post you spell recipes wrong, could you have done that in your file name?

 

     Yes, I did. Good catch. I was really worried and checked, it was only an error in my post not in the file.

 

 

 

 

7 hours ago, Gouki said:

Hi CounterBalance

 

In items.xml this part must not go together </item> </append>, </append> must go under </item>. 


This other part should also not go together <property name = "Weight" value = "5" /> <property name = "EconomicValue" value = "6" />. 

 

In recipes it should be like this:

 

<configs>
<append xpath = "/ recipes">
     <recipe name = "resourceBasicString" count = "1">
         <ingredient name = "resourceYuccaFibers" count = "6" />
     </recipe>
</append>
</configs>

 

You must always match the names to avoid any mistakes and make it quicker to identify them.
Hope that helps you.
Regards

 

  True indeed, those should be separate. It was only an issue in the post do to how it came out all clumped together when i pasted it from file. I tried to make it separate them all out to look like the file, but I guess I missed a few. In the mod itself it is appropriately spaced. Good eye though.

 

 

Link to comment
Share on other sites

6 hours ago, CounterBalance said:

 

   I didn't know about this. I followed the instructions. It seems the game does this automatically from the message it game me. I looked up the files and saw the recipes.xml and the items.xml.

     I saw all my append added to the file, but there were no additions and comments about my recipes append. The F1 had given me the error that my recipes mod had an xpath attribute missing and wasn't loaded to the game.

It would probably help us if you reproduced the error that you see when you hit F1.

 

Also - I want to back up and make sure this isn't a really basic error. The XML in the original post - you're not pasting this directly into the game's XML files, are you? You should be putting the code into your own XML files, in a subfolder called "Config" in your modlet's folder, which should be under the game's "Mods" folder.

 

I'm only asking because of the way you said you "saw all my append added to the file" - maybe it was just unclear to me.

Link to comment
Share on other sites

I have an update:

   I went ahead and copied another one of my mods recipes.xml file and pasted it to my own, then replaced it. After that I got my recipe and pasted over their mod. For some reason that worked to stop the error that my xpath has no set attribute. However, when I go into game I'm still unable to craft the item I coded, the item does still appear in the creative menu. I then went to the dump config files and saw that my recipe was indeed in there.

 

 image.thumb.png.a22a1aa8747aa09166728ee6da7527e5.png

 

 

So could my folder with mod files in it be corrupted somehow? If putting someone's else's file and writing over it worked?

Why is the item still not showing up to be crafted from backpack?

 

 

2 hours ago, khzmusik said:

It would probably help us if you reproduced the error that you see when you hit F1.

 

Also - I want to back up and make sure this isn't a really basic error. The XML in the original post - you're not pasting this directly into the game's XML files, are you? You should be putting the code into your own XML files, in a subfolder called "Config" in your modlet's folder, which should be under the game's "Mods" folder.

 

I'm only asking because of the way you said you "saw all my append added to the file" - maybe it was just unclear to me.

 

 

    Yes mods are in folder "mods" and yes in my mods folder I have a file called "Config" where the mod files are held.

I just mentioned that after the error and the many attempts to correct it had filed. I decided to then cut and past the recipe into the vanilla game files to see what would happen and it worked perfectly.  That is where I saw my append in the file confirming what I already saw in the game.

 

 

 

Link to comment
Share on other sites

Okay I thought about your question more and I think I understand.

  Yes the append I saw where all the items I had added. Like the Basic String, which were all in my modded folder within my config folder. Everyone of them was there, only the my append recipes where missing from the dump config files. So it accepted the items and localization files but seem to reject the modded recipes file without comment. Hopefully I explained it properly, I've been modding on and off for a while but first time talking to others about it so there is probably a better way to say what I'm trying to say.

   Hopefully the pic I posted above of the new dump config file helps.  That wasn't originally there the first time I looked it up as was suggested, but after the cut&paste I did there it was when i loaded up the game with no more xpath attribute missing error. Just not showing up to craft in game.

Link to comment
Share on other sites

I just tried exactly what you pasted here. It worked, I was able to craft the "resourceBasicString" item from plant fibers. (EDIT: though it scraps to cloth, which is odd, but that's something you can work on later.)

 

So I'm not sure exactly what is wrong, but it must have some kind of non-XML cause, like a bad filename or path or something.

 

I'm attaching a .zip file that has the entire contents of the modlet I created for testing. (Obviously the modlet itself is not named the same as yours, and the ModInfo.xml values are temporary.) Take a look at it and compare it to what you have now.

 

You could also try unzipping my test modlet into your own "Mods" directory (after removing your own modlet) and then seeing if it still works. If it doesn't, then maybe there's some kind of conflict between your modlet, and one of the other modlets you installed.

CounterBalanceTest.zip

Link to comment
Share on other sites

2 hours ago, khzmusik said:

I just tried exactly what you pasted here. It worked, I was able to craft the "resourceBasicString" item from plant fibers. (EDIT: though it scraps to cloth, which is odd, but that's something you can work on later.)

 

So I'm not sure exactly what is wrong, but it must have some kind of non-XML cause, like a bad filename or path or something.

 

I'm attaching a .zip file that has the entire contents of the modlet I created for testing. (Obviously the modlet itself is not named the same as yours, and the ModInfo.xml values are temporary.) Take a look at it and compare it to what you have now.

 

You could also try unzipping my test modlet into your own "Mods" directory (after removing your own modlet) and then seeing if it still works. If it doesn't, then maybe there's some kind of conflict between your modlet, and one of the other modlets you installed.

CounterBalanceTest.zip 1.53 kB · 0 downloads

 

Thanks a lot! The mod is working. Not sure how to close this post now. Now I can complete the mod. yes that is odd, about the cloth. I will have to test it, but my guess is that I copied the vanilla entry for that item as my base and just changed the name to Basic String. Not a big issue since you can make cloth from plant fiber in game so maybe just increase the plant fiber count to even it out so there isn't any exploit to get quick cloth, but having to make that then scrap for cloth seems unlikely. 

 

Thanks for all the time you put in to helping me  khzmusik .

 

Link to comment
Share on other sites

1 hour ago, CounterBalance said:

 

Thanks a lot! The mod is working. Not sure how to close this post now. Now I can complete the mod. yes that is odd, about the cloth. I will have to test it, but my guess is that I copied the vanilla entry for that item as my base and just changed the name to Basic String. Not a big issue since you can make cloth from plant fiber in game so maybe just increase the plant fiber count to even it out so there isn't any exploit to get quick cloth, but having to make that then scrap for cloth seems unlikely. 

 

Thanks for all the time you put in to helping me  khzmusik .

 

You're very welcome.

 

Also, I believe the "Material" property determines what it scraps into. Try using "Mplants" - that's what the plant fiber clothes use.

Link to comment
Share on other sites

On 12/27/2020 at 5:48 PM, khzmusik said:

You're very welcome.

 

Also, I believe the "Material" property determines what it scraps into. Try using "Mplants" - that's what the plant fiber clothes use.

   Actually I decided to go a different rout. After you said the cloth thing, I started thinking that it could be useful enough of a material that I could make it more costly to make by making it out of cloth rather than plant fiber to balance it out.

   Sadly I ran into another problem. I wanted to add the Basic String as a repair resource. I was able to get it added to the block, like other blocks seem to have (e.g. concrete needs concrete mix to repair), I also know you need to add that into the tool itself in the items.xml

   After fist saving my game files, I tested the concept in vanilla files, and it worked fine. However, that  isn't where I want to make changes so I made this xpath in my items mod  but got an error about how there was no basic string? I should have taken a picture but forgot:

<setattribute xpath="/items/item[start-with(@name='meleeToolRepair')]/property[@name='Allowed_upgrade_items']" name=
"value">resourceWood,resourceClayLump,resourceSnowBall,resourceScrapIron,resourceForgedIron,resourceForgedSteel,resourceConcreteMix,resourceCobblestones,ironDoor1_v1,vaultDoor01,scrapHatch_v1,vaultHatch_v1,resourceYuccaFibers,resourceCloth,resourceScrapPolymers,resourceBasicString</setattribute>

 

   I might have either set up the xpath wrong or I'm using the wrong xpath words.

 

My current solution is to create a whole new set of tools. I just tested it and it works, but for go through all of them make meshes for all eventually and so on will take time, not to mention if any changed are made to tools I will have to go back and fix all. Much rather have a line of xpath to go back to than all that. 

Thoughts?

 

 

Link to comment
Share on other sites

5 hours ago, CounterBalance said:

   Actually I decided to go a different rout. After you said the cloth thing, I started thinking that it could be useful enough of a material that I could make it more costly to make by making it out of cloth rather than plant fiber to balance it out.

   Sadly I ran into another problem. I wanted to add the Basic String as a repair resource. I was able to get it added to the block, like other blocks seem to have (e.g. concrete needs concrete mix to repair), I also know you need to add that into the tool itself in the items.xml

   After fist saving my game files, I tested the concept in vanilla files, and it worked fine. However, that  isn't where I want to make changes so I made this xpath in my items mod  but got an error about how there was no basic string? I should have taken a picture but forgot:

<setattribute xpath="/items/item[start-with(@name='meleeToolRepair')]/property[@name='Allowed_upgrade_items']" name=
"value">resourceWood,resourceClayLump,resourceSnowBall,resourceScrapIron,resourceForgedIron,resourceForgedSteel,resourceConcreteMix,resourceCobblestones,ironDoor1_v1,vaultDoor01,scrapHatch_v1,vaultHatch_v1,resourceYuccaFibers,resourceCloth,resourceScrapPolymers,resourceBasicString</setattribute>

 

   I might have either set up the xpath wrong or I'm using the wrong xpath words.

 

My current solution is to create a whole new set of tools. I just tested it and it works, but for go through all of them make meshes for all eventually and so on will take time, not to mention if any changed are made to tools I will have to go back and fix all. Much rather have a line of xpath to go back to than all that. 

Thoughts?

 

 

I didn't know you had to add the resource name to "Allowed_upgrade_items" - you learn something new every day!

 

With that in mind - your XPath is wrong:

 

  • The "Allowed_upgrade_items" property node, is a child of the property node with the "Action1" class (which specifies the "use" action, per the comments in the vanilla XML). Your existing XPath is looking for a property node, whose name is "Allowed_upgrade_items", that is a direct child of the item node.
  • The "setattribute" command is for adding an entirely new attribute, not for setting the value of an existing attribute. But I would do neither - I would append your resource to the end of the existing attribute value.
  • The conditional function is "starts-with" not "start-with".

Here's what I suggest:

<append xpath="/items/item[starts-with(@name='meleeToolRepair')]/property[@class='Action1']/property[@name='Allowed_upgrade_items']/@value">,resourceBasicString</append>

 

Link to comment
Share on other sites

3 hours ago, khzmusik said:

I didn't know you had to add the resource name to "Allowed_upgrade_items" - you learn something new every day!

 

With that in mind - your XPath is wrong:

 

  • The "Allowed_upgrade_items" property node, is a child of the property node with the "Action1" class (which specifies the "use" action, per the comments in the vanilla XML). Your existing XPath is looking for a property node, whose name is "Allowed_upgrade_items", that is a direct child of the item node.
  • The "setattribute" command is for adding an entirely new attribute, not for setting the value of an existing attribute. But I would do neither - I would append your resource to the end of the existing attribute value.
  • The conditional function is "starts-with" not "start-with".

Here's what I suggest:


<append xpath="/items/item[starts-with(@name='meleeToolRepair')]/property[@class='Action1']/property[@name='Allowed_upgrade_items']/@value">,resourceBasicString</append>

 

 

I copied and pasted what you wrote to avoid any typos on my part. I pressed f1 saw no error messages, went into the config dump files and it seems it did accept the append, , but my nail gun still wont use the string.

 

<append xpath="/items/item[starts-with(@name='meleeToolRepair')]/property[@class='Action1']/property[@name='Allowed_upgrade_items']/@value"><!--Element appended by: "My First Modlet"-->,resourceBasicString</append>

 

 

 

 

Link to comment
Share on other sites

56 minutes ago, CounterBalance said:

 

I copied and pasted what you wrote to avoid any typos on my part. I pressed f1 saw no error messages, went into the config dump files and it seems it did accept the append, , but my nail gun still wont use the string.

 




<append xpath="/items/item[starts-with(@name='meleeToolRepair')]/property[@class='Action1']/property[@name='Allowed_upgrade_items']/@value"><!--Element appended by: "My First Modlet"-->,resourceBasicString</append>

 

 

 

 

From the comment in the code, it looks like the append tag was added to the game's XML files. That's not what you're supposed to do.

 

You need to put the append tag in your modlet's items.xml file. That tag also needs to be just below the root node (the configs tag), it can't be nested.

 

...Maybe it would help if you thought about it this way.

 

The XML that you put in your modlet's files, is not the same kind of XML that is in the game's files. The XML in the game's files represents static content that the game uses for configuration.

 

But the XML that you put in your modlet's XML file, represents a programming language. That programming language happens to use XML, the same way other games use Lua or C# or whatever.

 

In this programming language, each kind of XML node (append, set, etc.) represents a command in that programming language. Each command says "do something to XML nodes (or their attributes), located in the game's XML file that has a matching filename." The "xpath" attribute says which nodes (or attributes) to run that command on.

 

The content between the opening and closing command tags (if any) says what data to use when running this command. (EDIT: including other XML tags - this is considered data, so isn't parsed as commands.)

 

But 7D2D doesn't run any of these commands if they're put in the game's XML files, because 7D2D doesn't think that XML represents that programming language.

 

Does that make any sense? If not - then forget it, it was only meant to help.

Link to comment
Share on other sites

9 minutes ago, CounterBalance said:

 

I just checked it wasn't in the game's item.xml file it was in my mod folder.

Very odd. The only change should have been to the attribute, it shouldn't have added any XML tags.

 

Maybe that "append" tag was nested inside another "append" node in your items.xml file? If so, it would have been considered data, and just inserted as is.

 

What is the content of your items.xml file? What do you see when you look in the game's items.xml file if you do exportcurrentconfigs?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...