Question: Resume Label inside a loop - out then back in?

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

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

Post Reply
user1679
Posts: 789
Joined: Fri, 20. Jul 18, 23:20

Question: Resume Label inside a loop - out then back in?

Post by user1679 » Sun, 4. Jun 23, 02:38

If I have a loop that is iterating over a list of ships, will the loop properly iterate if using a resume_label from INSIDE the loop to temporarily jump to a code block outside and then another resume_label from that external code block to jump back into the loop?

I know it's not the most elegant piece of code but it's simple enough for what I need.

Example:

Code: Select all

<label name="start" />

<do_all exact="$ships.count" counter="$a">

    <!-- do some stuff -->
    
    <resume_label label="outOfLoop" />
    <label name="returnToLoop" />
    
    <!-- do more stuff -->

</do_all>

<!-- all done>
<resume_label label="start" />

<label name="outOfLoop" />

<!-- do a bunch of stuff using variables set inside the loop -->

<resume_label label="returnToLoop" />

jan12342203
Posts: 65
Joined: Sat, 14. May 16, 22:13
x4

Re: Question: Resume Label inside a loop - out then back in?

Post by jan12342203 » Sun, 4. Jun 23, 11:22

if your code that normaly would be inside the loop.. placed now outside.. is very large you can create its own file for it and call that with run_script.. or <include_interrupt_actions ref=""/>

run_script jumps in to the script.. and comes back where it has left it

Code: Select all

<do_for_each name="$_Entry" in="$_List">
   <run_script name="'scriptname'">
      <param name="PARAM_1" value="$_Entry"/>
      <param name="PARAM_2" value="$_Entry.knownname/>
      <param name="PARAM_3" value="$_Param3"/>
      <param name="DEBUG" value="$DEBUG"/>
      <save_retval name="RESULT" variable="$_Result"/>
   </run_script>
</do_for_each>
<include_interrupt_actions ref=""/> will copy and paste the code you define in an external file to where you have your <include_interrupt_actions ref=""/>
its visual better for you while coding and when it gets executed the code is then inside the loop

Post Reply

Return to “X4: Foundations - Scripts and Modding”