how to replace do_elseifs
Moderators: Scripting / Modding Moderators, Moderators for English X Forum
-
- Posts: 126
- Joined: Sat, 14. Mar 15, 15:16
how to replace do_elseifs
how do you replace a deep section of a cue in do_elseif
example in NPC_Staff.xml i needed to replace this section
<do_elseif value="event.param == 'cStaff_move'">
<abort_scripts entity="$actor" />
<do_if value="$actor.type == entitytype.pilot or $actor.type == entitytype.commander">
<remove_value name="$actor.$shiptrader_docking" />
</do_if>
<dismiss_control_entity actor="$actor" object="$actor.container" />
</do_elseif>
dismiss_control_entity is creating a bug where on a player owned station with 2 managers, when you remove the one who is not managing the station, the real manager loses control of the station and it will no longer show 'managing _____'
i had to do this instead and it replaces the entire cue when i only needed a small portion of it
<replace sel='/mdscript[@name="NPC_Staff"]/cues/cue[@name="OnPlatformPopulation_Staff"]/cues/cue[@name="SectionHandler"]'>
[/b]
example in NPC_Staff.xml i needed to replace this section
<do_elseif value="event.param == 'cStaff_move'">
<abort_scripts entity="$actor" />
<do_if value="$actor.type == entitytype.pilot or $actor.type == entitytype.commander">
<remove_value name="$actor.$shiptrader_docking" />
</do_if>
<dismiss_control_entity actor="$actor" object="$actor.container" />
</do_elseif>
dismiss_control_entity is creating a bug where on a player owned station with 2 managers, when you remove the one who is not managing the station, the real manager loses control of the station and it will no longer show 'managing _____'
i had to do this instead and it replaces the entire cue when i only needed a small portion of it
<replace sel='/mdscript[@name="NPC_Staff"]/cues/cue[@name="OnPlatformPopulation_Staff"]/cues/cue[@name="SectionHandler"]'>
[/b]
-
- Moderator (Script&Mod)
- Posts: 14571
- Joined: Sun, 20. Nov 05, 22:45
no need to specify the full path.. especially in MD where cue names in each md script need to be unique a sel path like this is enough (same effect as your long sel above replacing the whole cue):
//cue[@name="SectionHandler"]
and, if thats the only <dismiss_control_entity /> inside the whole cue, you can select it with this:
//cue[@name="SectionHandler"]//dismiss_control_entity
and go up there one level to select the parent node:
//cue[@name="SectionHandler"]//dismiss_control_entity/..
alternatively you can also look for an <do_elseif/> which contains a <dismiss_control_entity/>(same effect as above, but more intuitive):
//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]
hint if you are not sure about your XPath Selectors: many XML Editors can resolve them - your selection will work if it resolves to exactly one node or Attribute
PS for clarification: // is for selecting any node (or Attribute) inside the current node to which the selection applies, regardless of depth - / is only for selecting a node inside the current one
(or an attribute of the current node)
//cue[@name="SectionHandler"]
and, if thats the only <dismiss_control_entity /> inside the whole cue, you can select it with this:
//cue[@name="SectionHandler"]//dismiss_control_entity
and go up there one level to select the parent node:
//cue[@name="SectionHandler"]//dismiss_control_entity/..
alternatively you can also look for an <do_elseif/> which contains a <dismiss_control_entity/>(same effect as above, but more intuitive):
//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]
hint if you are not sure about your XPath Selectors: many XML Editors can resolve them - your selection will work if it resolves to exactly one node or Attribute

PS for clarification: // is for selecting any node (or Attribute) inside the current node to which the selection applies, regardless of depth - / is only for selecting a node inside the current one

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

-
- Posts: 1842
- Joined: Tue, 2. Nov 10, 02:20
It's worth noting that loosely defined patches like this can cause problems that can be hard to track down if more than one mod are editing a particular script.UniTrader wrote:and, if thats the only <dismiss_control_entity /> inside the whole cue, you can select it with this:
//cue[@name="SectionHandler"]//dismiss_control_entity
and go up there one level to select the parent node:
//cue[@name="SectionHandler"]//dismiss_control_entity/..
alternatively you can also look for an <do_elseif/> which contains a <dismiss_control_entity/>(same effect as above, but more intuitive):
//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]
For more specific path selection, there's a code to insert for apostrophe that I can't remember off the top of my head, or you can use contains, for example:
<add sel="//cue[@name='OnPlatformPopulation_Staff']/actions/do_elseif[contains(@value,'event_cue_signalled')]" >
-
- Posts: 2963
- Joined: Tue, 18. Nov 14, 16:23
' used like this:Vim Razz wrote:For more specific path selection, there's a code to insert for apostrophe that I can't remember off the top of my head,
Code: Select all
do_elseif[@value="event.param == 'cStaff_move'"]
-
- Posts: 421
- Joined: Wed, 22. Jul 09, 22:31
Actually happened between Automated Emergency Jump and a carrier mod (forgot which one).Vim Razz wrote:It's worth noting that loosely defined patches like this can cause problems that can be hard to track down if more than one mod are editing a particular script.
I would always go with the most explicit path.
-
- Posts: 126
- Joined: Sat, 14. Mar 15, 15:16
Brilliant !!UniTrader wrote:no need to specify the full path.. especially in MD where cue names in each md script need to be unique a sel path like this is enough (same effect as your long sel above replacing the whole cue):
//cue[@name="SectionHandler"]
and, if thats the only <dismiss_control_entity /> inside the whole cue, you can select it with this:
//cue[@name="SectionHandler"]//dismiss_control_entity
and go up there one level to select the parent node:
//cue[@name="SectionHandler"]//dismiss_control_entity/..
alternatively you can also look for an <do_elseif/> which contains a <dismiss_control_entity/>(same effect as above, but more intuitive):
//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]
hint if you are not sure about your XPath Selectors: many XML Editors can resolve them - your selection will work if it resolves to exactly one node or Attribute
PS for clarification: // is for selecting any node (or Attribute) inside the current node to which the selection applies, regardless of depth - / is only for selecting a node inside the current one(or an attribute of the current node)

-
- Posts: 126
- Joined: Sat, 14. Mar 15, 15:16
question :
in section handler there were two doelseifs with a dismiss_control_entity within them.
1. <do_elseif value="event.param == 'cStaff_workhere'">
2. <do_elseif value="event.param == 'cStaff_move'">
only in cStaff_workhere the 'dismiss_control_entity' is within another do_if set. is ... <replace sel='//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]' >
going to replace both occurrence ?
in section handler there were two doelseifs with a dismiss_control_entity within them.
1. <do_elseif value="event.param == 'cStaff_workhere'">
2. <do_elseif value="event.param == 'cStaff_move'">
only in cStaff_workhere the 'dismiss_control_entity' is within another do_if set. is ... <replace sel='//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]' >
going to replace both occurrence ?
-
- Moderator (Script&Mod)
- Posts: 14571
- Joined: Sun, 20. Nov 05, 22:45
also keep the other posts in mind - mine was just meant as example what you can use as identifier besides attributes and how you can make your expressions shorter, but in no way intended to be a definite solution because i couldnt look up the original scripts at the time i posted it. after reading it a second time i should have been clearer about this.
also regarding compatibility: i prefer clarity/readability to have shorter paths because they have less points in the chain which can break and are also better understandable imo (i usually select them in such a way that you can see all parts of the path with collapsed nodes without scrolling, starting with a completely unique node like the cue name in MD)
also regarding compatibility: i prefer clarity/readability to have shorter paths because they have less points in the chain which can break and are also better understandable imo (i usually select them in such a way that you can see all parts of the path with collapsed nodes without scrolling, starting with a completely unique node like the cue name in MD)
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
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

-
- Posts: 2963
- Joined: Tue, 18. Nov 14, 16:23
I just doled off wrong information in a different thread, so I'm very conscious of my non-programmerness at the moment; but I believe that a sel= path has to resolve to only one node. If there are multiple possible targets, then it gets skipped, and you get a helpful message to that effect in the debug log.J3ANP3T3R wrote:only in cStaff_workhere the 'dismiss_control_entity' is within another do_if set. is ... <replace sel='//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]' >
going to replace both occurrence ?
-
- Posts: 126
- Joined: Sat, 14. Mar 15, 15:16
UniTrader wrote:also keep the other posts in mind - mine was just meant as example what you can use as identifier besides attributes and how you can make your expressions shorter, but in no way intended to be a definite solution because i couldnt look up the original scripts at the time i posted it. after reading it a second time i should have been clearer about this.
also regarding compatibility: i prefer clarity/readability to have shorter paths because they have less points in the chain which can break and are also better understandable imo (i usually select them in such a way that you can see all parts of the path with collapsed nodes without scrolling, starting with a completely unique node like the cue name in MD)
well thank you it seems to have worked. it seems to have replaced the _move section and not the _workhere section which also have its own dismiss_ .. i actually agree on the 'clarity/readability' i try to make patches shorter so they are less likely to conflict with other mods but i can only do so base on my knowledge ( which is little ). may i also ask how do you replace a particular line of code ? for example ... the <add_player_choice_return text="{1002,2}" position="bottom_right" comment="Goodbye"/> inside a cue .... i want to replace it with something else.
-
- Posts: 126
- Joined: Sat, 14. Mar 15, 15:16
w.evans wrote:I just doled off wrong information in a different thread, so I'm very conscious of my non-programmerness at the moment; but I believe that a sel= path has to resolve to only one node. If there are multiple possible targets, then it gets skipped, and you get a helpful message to that effect in the debug log.J3ANP3T3R wrote:only in cStaff_workhere the 'dismiss_control_entity' is within another do_if set. is ... <replace sel='//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]' >
going to replace both occurrence ?
i see thanks ... i was hoping this line ,
<replace sel='//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]' >
would only select a do_elseif with a 'dismiss_control_entity' command immediately after the do_elseif
do_elseif
dismiss_control_entity
and not
do_elseif
do_if
dismiss_control_entity
-
- Moderator (Script&Mod)
- Posts: 14571
- Joined: Sun, 20. Nov 05, 22:45
in this case not that helpful - it is the same message as for a path which resolves to no node at all ( cannot match path )w.evans wrote:I just doled off wrong information in a different thread, so I'm very conscious of my non-programmerness at the moment; but I believe that a sel= path has to resolve to only one node. If there are multiple possible targets, then it gets skipped, and you get a helpful message to that effect in the debug log.J3ANP3T3R wrote:only in cStaff_workhere the 'dismiss_control_entity' is within another do_if set. is ... <replace sel='//cue[@name="SectionHandler"]//do_elseif[dismiss_control_entity]' >
going to replace both occurrence ?
@J3ANP3T3R
jep, its afaik only for the directly nested node, but you can also specify more contained nodes and arguments there, like (just an example):
//do_elseif[do_if/dismiss_control_entity/@object="$actor.container"]
this would resolve to the do_elseif containing a do_if, which contains a dismiss command with the object attribute $actor.container
for the replace action (path only exemplary based on the node you have posted. i suggest you extend it/go up to to the containing cue - also i assume you want to put a add_player_choice_sub there in the script instead):
<replace sel='//add_player_choice_return[@position="bottom_right"]' ><add_player_choice_sub .......... /></replace>
keep also in mind that this is very likely to confict if thats the only non-mandatory item in this menu as i suspect - i suggest to use another part in the dialogue to put your item in.
Also note that the replace action replaces one node with another node, in my expierience it doesnt work for replacing one node with two other ones (i could be wrong there, thouth) if thats your intention - but there are alternatives to this

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

-
- Posts: 2963
- Joined: Tue, 18. Nov 14, 16:23
I like this thread. I'm learning stuff that isn't in the XML thread
These two:
should resolve to the two instances of dismiss_control_entity in NPC_Staff. However, the first will break if a mod or a future update were to add another <do_if value="$oldstaff.customhandler"> anywhere under <cue name="SectionHandler">. The second will break if a <do_elseif value="event.param == 'cStaff_move'"> is added anywhere under <cue name="SectionHandler">
can be substituted for the second sel path, but will break if any do_elseif nodes are added before the one referenced so that it's no longer the 9th do_elseif directly under /cue/actions
could also be used to refer to the first instance of dismiss_control_entity since it looks like <do_if value="@$container.controlentity.{$actor.type}"> is unique in the file, but it will break if another do_if with the same value is added anywhere in NPC_Staff.xml
These two:
Code: Select all
sel="//cue[@name='SectionHandler']//do_if[@value='$oldstaff.customhandler']/dismiss_control_entity"
Code: Select all
sel="//cue[@name='SectionHandler']//do_elseif[@value='event.param == 'cStaff_move'']/dismiss_control_entity"
Code: Select all
sel="//cue[@name='SectionHandler']/actions/do_elseif[9]//dismiss_control_entity"
Code: Select all
sel="//do_if[@value='@$container.controlentity.{$actor.type}']//dismiss_control_entity"
-
- Moderator (Script&Mod)
- Posts: 14571
- Joined: Sun, 20. Nov 05, 22:45
i would only use the position ( [9] ) if there is really no other possibility (attributes, sub-Nodes, etc.) - far too likely to break by other changes
for the other posibility of a unique node: i meant more like a cue name or @comment by EGO which is very unlikely to change or be duplicated
or a label which marks the beginning of the related code piece, like with this:
//label[@name="LABEL"]/following-sibling::XPath_after_this_label
just found a site which explains this and other useful XPath stuff
expressions which really have only one purpose and make no sense in other contexts are also fine, but these are more like a last resort
for the other posibility of a unique node: i meant more like a cue name or @comment by EGO which is very unlikely to change or be duplicated

//label[@name="LABEL"]/following-sibling::XPath_after_this_label
just found a site which explains this and other useful XPath stuff
expressions which really have only one purpose and make no sense in other contexts are also fine, but these are more like a last resort
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
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

-
- Posts: 126
- Joined: Sat, 14. Mar 15, 15:16