Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: Sushi on October 06, 2011, 03:09:28 pm

Title: Staggering when-argument events
Post by: Sushi on October 06, 2011, 03:09:28 pm
Example scenario: I have three dozen ships that I want to warp out, randomly staggered within a 3 second interval. I have a when-argument SEXP as follows (forgive the butchered syntax, hopefully it conveys the idea):

- when-argument
   - (big long list of ships)
   - is-event-true-msecs
        - myEvent
        - rand-multiple 0 3000
   - add-goal
        - <argument>
        - ai-warp

(trigger-count 999999, interval 0)

This doesn't work the way I would have hoped. Everything still happens for all of the ships at the same time. What should I be doing instead?

Title: Re: Staggering when-argument events
Post by: mjn.mixael on October 06, 2011, 03:15:31 pm
I don't know the answer off the top of my head right now.. (been UVing the Arcadia for a few hours and my brain is fried).. but I'm pretty sure the answer is somewhere in this tutorial. (http://www.hard-light.net/wiki/index.php/Tutorial_-_Conditional_Arguments)
Title: Re: Staggering when-argument events
Post by: Sushi on October 06, 2011, 03:24:29 pm
Just thought of something that might work, I'll try it when I get home. Basically, use random-of to choose one ship at a time, and use a variable to keep track of when to trigger the next one.

So basically:

- when-argument
    - random-multiple-of
        (big list of ships)
    - is-event-true-msecs
        - myEvent
        - $nextTime
    -add-goal
        - <argument>
        - <ai-warp>
    -modify-variable
        - $nextTime
        - +
            - rand-multiple(0, 300)
            - $nextTime
     -invalidate-argument
        - <argument>

Assuming this works the way I expect, it would mean the time to launch everything would be somewhere between (millis-per-frame * number of ships) and (300 * number of ships) milliseconds.

If I wanted to do them all in order (with random gaps between), i could just use in-sequence instead of random-multiple-of, right?
Title: Re: Staggering when-argument events
Post by: mjn.mixael on October 06, 2011, 03:30:10 pm
Assuming this works the way I expect, it would mean the time to launch everything would be somewhere between (millis-per-frame * number of ships) and (300 * number of ships) milliseconds.

If I wanted to do them all in order (with random gaps between), i could just use in-sequence instead of random-multiple-of, right?

This might be the case regardless.. but trigger count should work, barring that an every-time might be warranted and do the same thing without a variable.

This is an intriguing event.. I think I'll play around with it and let you know what I come up with.
Title: Re: Staggering when-argument events
Post by: Sushi on October 06, 2011, 03:33:50 pm
Thanks for that link... the "Under the hood" section at the list explains exactly why I'm seeing the behavior I am with my first attempt.

It also looks like my second attempt is likely to work (using either random-multiple-of or in-sequence). Woohoo!
Title: Re: Staggering when-argument events
Post by: mjn.mixael on October 06, 2011, 03:44:58 pm
Thanks for that link... the "Under the hood" section at the list explains exactly why I'm seeing the behavior I am with my first attempt.

It also looks like my second attempt is likely to work (using either random-multiple-of or in-sequence). Woohoo!

It does, I just checked.  :)
Title: Re: Staggering when-argument events
Post by: Cyborg17 on October 06, 2011, 04:50:40 pm
Just a note: the expected time for all the ships to be given order to jump out will be something like (0 + 300/2)*(number of ships).  If the number of ships is really is 36, then the expected value for that random-multiple sexp will end up being 5.4 seconds.  The total range is pretty extreme as well.  It can be anywhere from 36 microseconds (maybe?...) to 10.8 seconds.  You might want to try something like 50 and 116.  The expected time is 3 seconds and it has a smaller possible range. Between 1.8 and 4.16 seconds.  It's probably more realistic.
Title: Re: Staggering when-argument events
Post by: Sushi on October 06, 2011, 05:49:29 pm
Yeah, I just picked that "300" number out of a hat. And three dozen was just for an example.

What I really want this for is having properly-staggered launches for Diaspora vipers and raiders (from launch tubes and raider racks, respectively). Can't wait to get home and try this.
Title: Re: Staggering when-argument events
Post by: karajorma on October 06, 2011, 07:27:31 pm
Thanks for that link... the "Under the hood" section at the list explains exactly why I'm seeing the behavior I am with my first attempt.

Actually it would be possible to get the behaviour you want with any-of or number-of. What was preventing them from working was that the trigger for your SEXP didn't use <argument> in it anywhere. When that happens the game just assumes you want to do everything to all the ships on the list.
Title: Re: Staggering when-argument events
Post by: mjn.mixael on October 06, 2011, 08:26:25 pm
Thanks for that link... the "Under the hood" section at the list explains exactly why I'm seeing the behavior I am with my first attempt.

Actually it would be possible to get the behaviour you want with any-of or number-of. What was preventing them from working was that the trigger for your SEXP didn't use <argument> in it anywhere. When that happens the game just assumes you want to do everything to all the ships on the list.

Well... loosely speaking, yes. However if we didn't want/need to use <argument> in the trigger, then we need random-of.
Title: Re: Staggering when-argument events
Post by: karajorma on October 06, 2011, 09:22:33 pm
Absolutely.

I just wanted to clarify exactly why the first version Sushi posted hadn't worked. I prefer a complete answer in any thread for next time someone stumbles across the same problem. :)
Title: Re: Staggering when-argument events
Post by: mjn.mixael on October 06, 2011, 09:38:52 pm
Hmm true... I admit that I was confused with a similar use of any-of for a while until I figured it out by trial and error.
Title: Re: Staggering when-argument events
Post by: Sushi on October 08, 2011, 11:29:12 pm
For the record, this works brilliantly well using random-of and a variable to keep track of the next trigger time.