Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: pulsarou on September 13, 2017, 08:13:16 am

Title: Looping instructions in SEXP
Post by: pulsarou on September 13, 2017, 08:13:16 am
Hello!

I wish that carriers executes statements in loop. How do It ?

For exemples : for every times,
1) go to waypoint A
2) when arrive at waypoint A, go to waypoint B
3) when arrive at waypoint B, cloak 1, 2, etc objects
4) uncloak 1a, 2a, etc objects
5 loop to 1)

Thanks for help.   :confused:
Title: Re: Looping instructions in SEXP
Post by: Goober5000 on September 13, 2017, 10:24:30 am
Use a state machine.

Code: [Select]
when
  and
    =
      current_state
      0
    are-waypoints-done
      your_ship
      waypoint_A
  add-goal
    your_ship
    ai-waypoints-once
      waypoint_B
      89
  modify-variable
    current_state
    1
Toggle Count: 9999

When you've handled all the possible values of current_state, set the value to 0 and add a goal to go back to waypoint_A again.
Title: Re: Looping instructions in SEXP
Post by: karajorma on September 13, 2017, 10:31:20 am
I don't think that will work. Doesn't waypoints-done use the mission log and return SEXP_KNOWN_TRUE if it found the waypoint done? Even with every-time that means it still wouldn't work.

Checking the distance from the waypoint should work though.
Title: Re: Looping instructions in SEXP
Post by: Goober5000 on September 14, 2017, 01:44:14 am
That's a good point; waypoints-done-delay does use the mission log.  A distance check is the correct thing to do.
Title: Re: Looping instructions in SEXP
Post by: pulsarou on September 14, 2017, 03:35:01 pm
Ok !

thanks for help. I' ll try that.