[TUTORIAL] XML Patch Guide

The place to discuss scripting and game modifications for X Rebirth.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

theqmann
Posts: 19
Joined: Fri, 21. Jan 11, 21:47
x4

Post by theqmann » Wed, 27. Nov 13, 08:41

Ah, I found it:

you have

Code: Select all

<add sel='//component[@name="character_deco_security_guard_01"]/properties/animations'> 
       <animation name="dancing01" ref="assets/characters/argon/animations/anim_decoration_dance" /> 
       <animation name="a_facepalm01" ref="assets/characters/animations/anim_a_facepalm_ar_fe_generic_01" lookat="0" /> 
</add> 
but the syntax needs to be

Code: Select all

<add sel="//component[@name='character_deco_security_guard_01']/properties/animations">
       <animation name="dancing01" ref="assets/characters/argon/animations/anim_decoration_dance" /> 
       <animation name="a_facepalm01" ref="assets/characters/animations/anim_a_facepalm_ar_fe_generic_01" lookat="0" /> 
</add>
Your quotes are switched on the sel statement!

The XML string assigned to the sel tag always needs to have "" on the outside, and only ' ' on the inside.

Skeeter
Posts: 3675
Joined: Thu, 9. Jan 03, 19:47
x3

Post by Skeeter » Wed, 27. Nov 13, 13:03

Are you sure that would make it work? The below code used the ' and " the way i did em before and worked ok without changing them around?

Code: Select all

<diff> 
<replace sel='###/component[@name="character_deco_security_guard_01"]/properties/animations/animation[@name="dancing01"]/@ref'>assets/characters/argon/animations/anim_decoration_dance</replace> 
<replace sel='###/component[@name="character_deco_security_guard_01"]/properties/sequences/sequence[@type="idle"]/transtions/transition[@animation="decoration01"]/@animation'>dancing01</replace>
</diff>
So im wondering why i have to have " after sel= now for the add command when ' worked for replace commands.

Edit - It did actually work tho when i tried it your way, cheers mate ur a star. I still find it strange tho that it worked with ' before with my first mod as was shown on page 1 of this thread. Still it works and im happy thats the main thing. :) Thx again.
[ external image ]
7600x cpu 5.4ghz 32gb DDR5 5600mhz 6700XT 32" 1440p mon

Goekhan
Posts: 51
Joined: Thu, 23. Jul 09, 21:11
x4

Post by Goekhan » Wed, 4. Dec 13, 18:00

Is "msel" supported?

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Thu, 5. Dec 13, 23:53

IMPORTANT NOTE FOR ADD OPERATION:

it is crucial that the add operation is completely in one line, otherwise the Newlines and spaces between the nodes seem to be interpreted as text and mess everything up. (just wasted about 3 hours before finding that..)

-> so before saving with a add Operation use the "Linarize XML" from your Editor of choice.
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

csaba
Posts: 1251
Joined: Fri, 26. Aug 05, 22:39
x4

Post by csaba » Sat, 7. Dec 13, 23:10

I'm having problem changing the tradeships range in trade.ship.xml. I tried quite some versions currently I'm sitting with this one after reading this thread from start to end. Seeing as traders are still not piling up at the DV-OM gate I have to think it's not working:


Code: Select all

 <diff>
	<replace sel="aiscript/attention/actions/do_else/do_if[@value='this.ship.isclass.ship_l or this.ship.isclass.ship_xl']/set_value[@name='$range']/@exact"> 
         this.ship.galaxy
	</replace>	
 </diff>
I want to change this:

Code: Select all

      <do_else>
        <do_if value="this.ship.isclass.ship_l or this.ship.isclass.ship_xl">
          <set_value name="$range" exact="this.ship.cluster" />
        </do_if>
        <do_else>
          <set_value name="$range" exact="this.ship.sector" />
        </do_else>
      </do_else>
To this:

Code: Select all

      <do_else>
        <do_if value="this.ship.isclass.ship_l or this.ship.isclass.ship_xl">
          <set_value name="$range" exact="this.ship.galaxy" />
        </do_if>
        <do_else>
          <set_value name="$range" exact="this.ship.sector" />
        </do_else>
      </do_else>
I don't want to put in Jey's mod just for this feature atm.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sat, 7. Dec 13, 23:22

MutantDwarf wrote:It really should be mentioned in the first post that all selection arguments need to point to a unique node; there can't be any ambiguity, and if there is the whole node will just be ignored and left unchanged.
there is another do_else node there.

but maybe this post helps you:
http://forum.egosoft.com/viewtopic.php? ... 54#4248754
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

andrewas
Posts: 1498
Joined: Thu, 10. Mar 05, 21:04
x3tc

Post by andrewas » Wed, 25. Dec 13, 02:37

UniTrader wrote:IMPORTANT NOTE FOR ADD OPERATION:

it is crucial that the add operation is completely in one line, otherwise the Newlines and spaces between the nodes seem to be interpreted as text and mess everything up. (just wasted about 3 hours before finding that..)

-> so before saving with a add Operation use the "Linarize XML" from your Editor of choice.
Also true for replace operations. Check for 'invalid character' warnings in the debug log. What a waste of time tonight was. Ten minutes coding, over an hour to get the patch working, two hours and counting to redo chapter 3 so I know everything works.

Challenge: Tell me one advantage of the XML scripting language and XML patch over a more conventional language and standard diffs.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Wed, 25. Dec 13, 03:11

andrewas wrote:Challenge: Tell me one advantage of the XML scripting language and XML patch over a more conventional language and standard diffs.
- diff can only change whole lines, xmldiff can change as little as an attribute without affecting the rest of the file line/node
- diff depends on line numbers or previous/next line context, which can change if multiple extensions change the same file in the same context (eg adding compatible missiles to a ship)
- there are already many standard editors available for xml which implement things like validation and auto-completion
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

mbhm
Posts: 78
Joined: Wed, 21. Mar 07, 18:13
x4

Post by mbhm » Fri, 3. Jan 14, 19:09

What about T-Files? Let's assume, you have a mod. Adding to the T-File should be easy like:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<diff>
  <add sel='//'>
    <page id="[yourPageNumber]" title="[yourTitle]" descr="0" voice="no">
    <t id="1">some text</t>
    <t id="2">some more text</t>
    <t id="3">etc</t>
    <t id="4">pp</t>
    </page>
  </add>
</diff>
But what, if you want to create a second mod without creating a new Pagefile?
You shouldn't force people to use both mods, just to have a proper t-File with the first mod adding the page and the second one adding to that page.
But how could you do something like "Add to the page or create it, if it doesn't exist" ?

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Fri, 3. Jan 14, 19:15

if you just want to add stuff i would suggest merge files instead of diff files ;) see 2nd Post ;) (basically a t-file like in the previous games which contains only your new stuff) - it is possible to have the same page in the file multiple times and it still works as intended ;) not sure what happens if you use the same page/t id twice though, altough i think the last loaded one wins.
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

mbhm
Posts: 78
Joined: Wed, 21. Mar 07, 18:13
x4

Post by mbhm » Sun, 5. Jan 14, 10:16

I have an interesting experience:

When using my mod loading a game, that wasn't modded before, i get the error messages:
[timestamp: 1388912148]: Error: LookupKeyName::LookupName(): The key name "sel" is not recognized in lookup 'ScriptXML'. Originated from: ""
[timestamp: 1388912148]: Error: Error loading MD file extensions\SIG\md\Smalltalk.xml: Invalid root node
Despite that the mod works normally.

The File starts with:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<diff>
  <replace sel='/mdscript/cues/cue[@name="SmalltalkSectionHandler"]'>

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sun, 5. Jan 14, 10:28

the Game tries to interpret the xml as merge file first, which is not succesful (because it doesnt know how to use the nodes in there with this method). afterwards it applies this file as diff file.
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

mbhm
Posts: 78
Joined: Wed, 21. Mar 07, 18:13
x4

Post by mbhm » Sun, 5. Jan 14, 10:41

So it's normal and nothing to worry about. Thank you.

danke
Posts: 146
Joined: Wed, 6. Nov 02, 20:31
x4

Post by danke » Mon, 6. Jan 14, 06:05

Source:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
  <bar> 
    <foo a="1"/> 
  </bar>
  </bar>
    <foo a="2"/> 
  </bar> 
</root>
Is there an XPath zu address the second foo (<foo a="2"/>)?
(<bar> is not unique.)

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Mon, 6. Jan 14, 06:13

for your example those would count:

/root/bar/foo[@a='2']
//bar/foo[@a='2']
//foo[@a='2']

as long as one of the sub-nodes has something unique the parent node doesnt need to be unique ;)

or you can also adress the nth node with this name using this mehthod:
/root/bar[2]/foo
although i would recommend the first method since its more reliable.

PS if you use an XML Editor it should have an "evaluate XPath"-function - if you are not sure that your XPath works then play around with that ;) in the end it should return only one result
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

danke
Posts: 146
Joined: Wed, 6. Nov 02, 20:31
x4

Post by danke » Mon, 6. Jan 14, 07:03

Thanks. The following XPaths are valid too:

/root/bar[2]
or
/root/bar[2]/foo

Edit: Ah. I see. You wrote the same.

brammie
Posts: 100
Joined: Thu, 19. Dec 13, 23:26

Post by brammie » Sun, 12. Jan 14, 04:03

just remember that bar[2] != bar[@a='2'],
the bar[2] is a referencee to the 2e bar child, the bar[@a=2] is all the bar's where the attribute a=2...

mbhm
Posts: 78
Joined: Wed, 21. Mar 07, 18:13
x4

Post by mbhm » Wed, 2. Jul 14, 09:17

An interesting thing i ran into:

What to do if you want to adress a node that compares a fixed value.
Like:

Code: Select all

<do_elseif value="param == 'xyz'">
going straight forward it would be like:

Code: Select all

<replace sel="/root/[whatever nodes]/do_elseif[@value='param == 'xyz'']" />
but i'm pretty sure that won't work. Do those inner single quotes get doubled [ '' ] or escaped [ \' ]?

User avatar
YorrickVander
Posts: 2702
Joined: Tue, 29. Oct 13, 21:59
x4

Post by YorrickVander » Wed, 2. Jul 14, 10:18

stackoverflow (<3 stackoverflow) has this to say

http://stackoverflow.com/questions/1240 ... g-function

Worth a try if /' doesn't work.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

lhotski
Posts: 82
Joined: Thu, 10. Oct 13, 17:10
x3ap

Post by lhotski » Sun, 20. Jul 14, 03:33

How to replace one attribute of multiple same name nodes in a config file, e.g. libraries/targetpoints.xml?

Part of source:

Code: Select all

<targetpoints>
  ...
  <pointlist macro="struct_bt_dv_water_destillery_macro" tags="ship_xs hack">
    <point x="-368.217" y="526.846" z="-2913.74" r="50" comment="surface"/>
    <point x="-364.932" y="504.835" z="-3094.52" r="50" comment="surface"/>
    <point x="-1426.63" y="680.695" z="62.918" r="50" special="1"
comment="surface"/>
    ...
  </pointlist>
  ...
</targetpoints>
Variations like

Code: Select all

<replace sel="//point/@r">500</replace>
both

Code: Select all

<replace sel="*/point/@r>500</replace>
does not work. I've seen the validation error in debug log:

Code: Select all

[=ERROR=] Cannot match path '//point/@r' in patch file 'extensions\simplehack\libraries\targetpoints.xml'. Skipping node.

Post Reply

Return to “X Rebirth - Scripts and Modding”