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

Why does this code not work?

I'm trying to shorten a previous code:
 
<append xpath="/items/item[@name='gunMGT0PipeMachineGun']/property[@class='Action0']/property[@name='Magazine_items']/@value">,ammo762mmBulletStun</append>
<append xpath="/items/item[@name='gunRifleT0PipeRifle']/property[@class='Action0']/property[@name='Magazine_items']/@value">,ammo762mmBulletStun</append>
<append xpath="/items/item[@name='gunRifleT1HuntingRifle']/property[@class='Action0']/property[@name='Magazine_items']/@value">,ammo762mmBulletStun</append>
<append xpath="/items/item[@name='gunRifleT2LeverActionRifle']/property[@class='Action0']/property[@name='Magazine_items']/@value">,ammo762mmBulletStun</append>
<append xpath="/items/item[@name='gunRifleT3SniperRifle']/property[@class='Action0']/property[@name='Magazine_items']/@value">,ammo762mmBulletStun</append>

<append xpath="/items/item[@name='gunMGT1AK47']/property[@class='Action0']/property[@name='Magazine_items']/@value">,ammo762mmBulletStun</append>
<append xpath="/items/item[@name='gunMGT2TacticalAR']/property[@class='Action0']/property[@name='Magazine_items']/@value">,ammo762mmBulletStun</append>
<append xpath="/items/item[@name='gunMGT3M60']/property[@class='Action0']/property[@name='Magazine_items']/@value">,ammo762mmBulletStun</append>

<append xpath="/items/item[@name='gunMGT0PipeMachineGun']/property[@class='Action0']/property[@name='Magazine_items']/@value">,Scrap762mmAmmo</append>
<append xpath="/items/item[@name='gunRifleT0PipeRifle']/property[@class='Action0']/property[@name='Magazine_items']/@value">,Scrap762mmAmmo</append>
<append xpath="/items/item[@name='gunRifleT1HuntingRifle']/property[@class='Action0']/property[@name='Magazine_items']/@value">,Scrap762mmAmmo</append>
<append xpath="/items/item[@name='gunRifleT2LeverActionRifle']/property[@class='Action0']/property[@name='Magazine_items']/@value">,Scrap762mmAmmo</append>
<append xpath="/items/item[@name='gunRifleT3SniperRifle']/property[@class='Action0']/property[@name='Magazine_items']/@value">,Scrap762mmAmmo</append>

<append xpath="/items/item[@name='gunMGT1AK47']/property[@class='Action0']/property[@name='Magazine_items']/@value">,Scrap762mmAmmo</append>
<append xpath="/items/item[@name='gunMGT2TacticalAR']/property[@class='Action0']/property[@name='Magazine_items']/@value">,Scrap762mmAmmo</append>
<append xpath="/items/item[@name='gunMGT3M60']/property[@class='Action0']/property[@name='Magazine_items']/@value">,Scrap762mmAmmo</append>


In order to make it compatible with ALL weapons that use that ammo, in the case of someone using a mod that adds other weapons that use that same ammo type.
<append xpath="/items/item[starts-with(@name,'gun')]/property[@class='Action0']/property[@name='Magazine_items']/value[starts-with(@value,'ammo762')]/@value">,ammo762mmBulletStun,Scrap762mmAmmo</append>


However, the mentioned code doesn't work and doesn't even throw errors, it just refuses to show up, but the older codes worked perfectly fine, adding in the appropriate ammo to the options for the specific gun.

Anyone know of a way to fix this?

 
I am at work so I have no means of testing this, but why not try this instead

<append xpath="/items/item/property[@class='Action0']/property[@name='Magazine_items' and contains(@value,'ammo762')]/@value">,ammo762mmBulletStun,Scrap762mmAmmo</append>




Since you are changing all guns with 7.62 ammo for the magazine, you don't need to specify item.  This will point it to the magazine_items line and look for any that contain ammo762 in the value.  Then it should append your additions to the end.

I am using contain in my code and haven't had issues yet.  I have never used starts-wtih

For example, this is code I am using right now

    <set xpath="/items/item[@name='gunRifleT0PipeRifle']/effect_group/passive_effect[contains(@name,'ModSlots')]/@value">0</set>




Edit:  Sorry I copied and paste the wrong line of code to try

 
Last edited by a moderator:
That worked perfectly thanks! Saved me a TON of code


Glad I could be of assistance.

Looking at your original code, you might be able to use it with the same format I used with contains

<append xpath="/items/item[starts-with(@name,'gun')]/property[@class='Action0']/property[@name='Magazine_items']/value[starts-with(@value,'ammo762')]/@value">,ammo762mmBulletStun,Scrap762mmAmmo</append>




should probably be

<append xpath="/items/item[starts-with(@name,'gun')]/property[@class='Action0']/property[@name='Magazine_items' and starts-with(@value,'ammo762')]/@value">,ammo762mmBulletStun,Scrap762mmAmmo</append>




Since you had the extra hash tag in there between magazine items and value, the code was looking for another line of code.  With the and statement there, the code should be looking for lines that have Magazine_items and a value starting with ammo762.

so   /property[@name='Magazine_items']/value[starts-with(@value,'ammo762')]/@value">

becomes /property[@name='Magazine_items' and starts-with(@value,'ammo762')]/@value">

 
Back
Top