Question: get returning values from order in caller

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

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

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

Question: get returning values from order in caller

Post by ns88ns » Fri, 20. Oct 23, 10:45

Hi, Community.

When a new immediate order is created like below:

Code: Select all

<create_order ... immediate="true">
	order params ...
</create_order/>
<wait ... />
and the order script returns values like below:

Code: Select all

<return value=...>
	<retval ... />
</return>
After the immediate order is created - it interrupts the caller and runs. Then, how can I get the returning values from the order script in the caller, when the caller resumes?

Regards.

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13309
Joined: Sun, 15. Feb 04, 20:12
x4

Re: Question: get returning values from order in caller

Post by euclid » Sat, 21. Oct 23, 12:31

Hi :-)

In most cases "return" will just abort the current action but there are exceptions. For example if your caller is an MD script or a library then

Code: Select all

   <run_actions ref="md.MyMDScript" result="$MyResult">  
will return a named return value to the caller via "result".

Specifically the named return value "retval" is only supported for non-order AI scripts. Please check the common.xsd for more info.

However, I'm not sure what you are trying to do. If you would provide more info then there may be other ways to solve your problem.

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

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

Re: Question: get returning values from order in caller

Post by ns88ns » Sat, 21. Oct 23, 18:50

Hi, Euclid.

Thank you so much for reply and clarification. Sure, I need to explain my goal in more detail.

I'm playing with X4F scripting and implementing jumps for a certain ship (a quite specific ship with unique jump ability, that can be taken via a sub-story). The major problem is how to implement the jump process. I'm implementing it not as a separate order that can be called manually. Instead, I wish to implement it as a subprocess of generic movement implemented by the "move.generic" AI script. For that, I injected into the "move.generic" two conditional immediate calls of external AI script that does all the things. I prefer to keep all advanced functionality in external scripts and don't modify basic scripts too much.

By my idea, the initiated jump is an "unbreakable" process, so implementation via the "move.generic" raises a problem: the "move.generic" script can be aborted or interrupted. In this case, the entire stack of running child scripts is also aborted or interrupted and, finally, it breaks the jump. It is not what I need. Therefore I wish to implement jump via critical order which can't be aborted, canceled or interrupted. The jump script is guaranteed to be done in the defined time so it is safe to run it as a critical order.

The jump script itself performs some post-processing checks and should report the result to the caller (e.g. destination object was destroyed and the jump hasn't been done). So, when I create a critical order, the order will run and interrupt the caller. After the critical order is done - the caller resumes and has to process the result from the jump order. I thought of using ship blackboard to save the result but it is not safe because there are cases when the caller can be aborted before the jump order is done and won't clean the temporarily stored jump result.

Now Implemented returning of result from the critical jump order via callback with <signal_object>. E.g., in the jump caller:

Code: Select all

<create_order ... immediate="true" comment="critical jump order">
	order params
</create_order>
<wait exact="timeout">
	<interrupt>
		<condition>
			<event_object_signalled object="this.ship" param="signal"/>
		</condition>
		<actions>
			... handle the callback from jump order ...
		</actions>
	</interrupt>
</wait>
The delayed callback In the Jump order:

Code: Select all

<signal_objects object="this.ship" param="signal" param2="<jump_result>" delay="small delay" comment="a small delay is required"/>
<returm/>
It works. Even if the caller is aborted - the jump will done and the jump result will just gone because the signal won't be processed. It is OK. Though it looks ... too cumbrous. So, I'm looking for a more elegant implementation (or at least ideas about that)... Perhaps, there is a way to run a child script as a "critical" script?

Best regards.

Return to “X4: Foundations - Scripts and Modding”