Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: karajorma on March 02, 2011, 11:23:26 pm

Title: When When, When Every-Time
Post by: karajorma on March 02, 2011, 11:23:26 pm
There seems to be a lot of confusion surrounding every-time. People are still using it because they want something to happen every frame. That's not what it is for and is, in fact, a side effect of its true usage. If you want something to happen every frame you should be using when with a high repeat or trigger count and a delay of 0.

Every-time is a specialist SEXP that is only really needed in certain situations. The SEXP system has a habit of deciding that certain SEXPs only need to be evaluated until they come true. After that there is no way they can become untrue so there is no need to re-evaluate them every single frame. Same goes for events that are false and can never come true. Why check if a ship is destroyed once it's already departed for instance? For example suppose you have this repeating event.

Code: [Select]
when
-is-destroyed-delay
--0
--Aries 1

Once Aries has been destroyed it's never going to be undestroyed so the game sees no point in wasting CPU time checking. It just marks the entire SEXP as SEXP_KNOWN_TRUE. 99% of the time this is the right thing to do. The game would be wasting time checking this stuff every frame.

But what if you have this repeating event?

Code: [Select]
when
-is-destroyed-delay
--I'mAVariable[0]
--Aries 1
-modify-variable
--I'mAVariable[0]
-- +
---I'mAVariable[0]
---60

Now we have a problem. After the first time the event triggers the game will mark the entire SEXP as true forever, even though the modify variable SEXP has now set the delay to 60 seconds. That means the event will keep triggering every frame even though it should only trigger once a minute.

This is when you need every-time. Every-time ignores all the SEXP_KNOWN_TRUE/FALSE stuff and just resets the entire event to unknown after every time it runs. That's why you can't use is-event-true with it. The above SEXP would work with every-time.


So here's a list of SEXPs you might see different results with when/every-time.

key-pressed
is-destroyed-delay
is-subsystem-destroyed-delay
has-docked-delay
has-undocked-delay
has-arrived-delay
has-departed-delay
is-disabled-delay
is-disarmed-delay
waypoints-done-delay
ship-type-destroyed
has-time-elapsed
percent-ships-disarmed
percent-ships-departed
percent-ships-disabled
percent-ships-destroyed
percent-ships-arrived
depart-node-delay
departed-or-destroyed-delay
is-cargo-known-delay
cap-subsys-cargo-known-delay
has-been-tagged-delay

All the goal SEXPs (including the previous-goal ones).
All the event SEXPs (including the previous-event ones).

speed
set-jumpnode-model
targeted
facing

These SEXPs will also sometimes return SEXP_NAN_FOREVER. It might be possible to make them evaluate to a sensible number later though.

distance
distance-subsystem
get-object-speed
get-object-angle

These SEXPs will also sometimes return SEXP_NAN_FOREVER. You probably can't make them evaluate to a sensible number once you've had them return false once though. I've included them for completeness.

special-warp-distance
shields-left
hits-left
hits-left-subsystem
sim-hits-left
is-ship-visible
is-ship-stealthy
is-friendly-stealth-visible
special-warpout-name
Title: Re: When When, When Every-Time
Post by: zookeeper on March 03, 2011, 01:02:45 am
Oh... :eek2: Thanks, that's good to know.
Title: Re: When When, When Every-Time
Post by: FelixJim on March 17, 2011, 04:17:27 pm
Insert this into the pinned advanced lessons please? It's something which is really useful to know.
Title: Re: When When, When Every-Time
Post by: karajorma on March 18, 2011, 01:07:08 am
Okay, Edited my stickied tutorial with a link back here.
Title: Re: When When, When Every-Time
Post by: FelixJim on March 18, 2011, 02:39:06 pm
Champion. A list of links to topics like this would be a powerful resource to FREDers like me who basically know what they're doing but aren't anything like experts (I believe this comprises a large chunk of the FREDing community).
Title: Re: When When, When Every-Time
Post by: karajorma on March 19, 2011, 08:41:42 pm
Well I posted this one cause even most of the experts were getting it wrong. I think only myself, Goober and maybe FUBAR (The 3 FREDders who are also coders) were really aware of what every-time was actually for.