[Question] Behavior of AI wait command

The place to discuss scripting and game modifications for X4: Foundations.

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

ns88ns
Posts: 91
Joined: Sun, 11. Sep 11, 22:00
x4

[Question] Behavior of AI wait command

Post by ns88ns »

Hi, community and scripting experts.

I faced odd behavior of blocking command <wait/> in AI scripts - it is never done. I'm investigating original script "trade.find.commander.xml" (v2.60) and made following diff patch:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<diff>
	<add sel="//attention/actions/do_if[@value='$buyoffers.count gt 0']/do_all[@exact='$buyspaces.count']/do_all[@exact='$buyoffers.count']/do_if[@value='$buyoffers.{$i}.available']/wait" pos="before">
		<debug_text text="'wait started'" chance="$debugchance"/>
	</add>
	<add sel="//attention/actions/do_if[@value='$buyoffers.count gt 0']/do_all[@exact='$buyspaces.count']/do_all[@exact='$buyoffers.count']/do_if[@value='$buyoffers.{$i}.available']/wait" pos="after">
		<debug_text text="'wait done'" chance="$debugchance"/>
	</add>
</diff>
There is just one command between these debug messages:

Code: Select all

<wait min="5s" max="10s"/>
so, final code must be (I expect it at least):

Code: Select all

<debug_text text="'wait started'" chance="$debugchance"/>
<wait min="5s" max="10s"/>
<debug_text text="'wait done'" chance="$debugchance"/>
Nothing more there. I expect both the messages must be printed. First debug message is printing well, but second - is printing never.

Why? There are no any error in debug log.

Thank you.
ns88ns
Posts: 91
Joined: Sun, 11. Sep 11, 22:00
x4

Re: [Question] Behavior of AI wait command

Post by ns88ns »

I have found and read this topic X Rebirth Official Tools, exactly the ection "AI Scripts". Can't understand following:
  • You SHOULD NOT move blocking actions in or out of blocks of a repeating <do_all> (e.g. with exact, min, or max attribute).
  • You SHOULD NOT change the counter variable name of a repeating <do_all> if it contains blocking actions.
My complete diff of "trade.find.commander.xml" if:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<diff>
	<add sel="//attention/actions" pos="prepend">
		<do_if value="this.isplayerowned">
			<set_value name="$debugchance" exact="100"/>
			<set_value name="$debugchance2" exact="100"/>
		</do_if>
	</add>
	<add sel="//attention/actions/do_if[@value='$homebase.isoperational']/do_if[@value='$basketchanged?']" pos="prepend">
		<do_if value="this.isplayerowned">
			<create_list name="$warebasketverified"/>
			<do_all exact="$warebasket.count" counter="$i1">
				<set_value name="$waretoverify" exact="$warebasket.{$i1}"/>
				<do_if value="$resources.indexof.{$waretoverify} or $products.indexof.{$waretoverify} or $tradewares.indexof.{$waretoverify} or $supplyresources.indexof.{$waretoverify}">
					<append_to_list name="$warebasketverified" exact="$warebasket.{$i1}"/>
				</do_if>
			</do_all>
			<do_if value="$warebasketverified.count">
				<set_value name="$locwares" exact="$warebasketverified.clone"/>
			</do_if>
			<remove_value name="$i1"/>
			<remove_value name="$warebasketverified"/>
			<remove_value name="$waretoverify"/>
		</do_if>
	</add>

	<!-- trace of execution of some WAIT commands -->
	<add sel="//attention/actions/do_if[@value='$homebase.isoperational']/do_if[@value='$basketchanged?']/do_if[@value="@this.assignedcontrolled.order.id == 'TradeRoutine'"]/wait[@exact='1ms']" pos="before">
		<debug_text text="'wait P1 started'" chance="$debugchance"/>
	</add>
	<add sel="//attention/actions/do_if[@value='$homebase.isoperational']/do_if[@value='$basketchanged?']/do_if[@value="@this.assignedcontrolled.order.id == 'TradeRoutine'"]/wait[@exact='1ms']" pos="after">
		<debug_text text="'wait P1 done'" chance="$debugchance"/>
	</add>
	<add sel="//attention/actions/do_if[@value='$buyoffers.count gt 0']/do_all[@exact='$buyspaces.count']/do_all[@exact='$buyoffers.count']/do_if[@value='$buyoffers.{$i}.available']/wait" pos="before">
		<debug_text text="'wait P2 started'" chance="$debugchance"/>
	</add>
	<add sel="//attention/actions/do_if[@value='$buyoffers.count gt 0']/do_all[@exact='$buyspaces.count']/do_all[@exact='$buyoffers.count']/do_if[@value='$buyoffers.{$i}.available']/wait" pos="after">
		<debug_text text="'wait P2 done'" chance="$debugchance"/>
	</add>
</diff>
This code doesn't cause errors (at least I don't see them in debug log). And message "wait P* done" is never printed... Could somebody explain?

Thank you.
Mysterial
Posts: 664
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [Question] Behavior of AI wait command

Post by Mysterial »

Well, for the first one, edit_order_param causes the order to be restarted, so the next wait is guaranteed not to return. That is in fact why the wait is even there; since the restart effect is latent, they don't want the script to halfway execute a bunch of stuff for no reason.

For the second one, assuming no user error, it looks like it should print. But the code won't get in there every time and various other interrupts could still happen. Editing the wait time down might make it easier to see.
ns88ns
Posts: 91
Joined: Sun, 11. Sep 11, 22:00
x4

Re: [Question] Behavior of AI wait command

Post by ns88ns »

Oh, yes, really.
edit_order_param causes the order to be restarted
It actually was the cause.

Thank you so much for the usefull hint.

Return to “X4: Foundations - Scripts and Modding”