Author Topic: When When, When Every-Time  (Read 1922 times)

0 Members and 1 Guest are viewing this topic.

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
When When, When Every-Time
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
« Last Edit: March 02, 2011, 11:35:17 pm by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: When When, When Every-Time
Oh... :eek2: Thanks, that's good to know.

  

Offline FelixJim

  • 28
  • User 11092
Re: When When, When Every-Time
Insert this into the pinned advanced lessons please? It's something which is really useful to know.
In-Mission Techroom Script v0.4 - See information from the techroom in game
Simple Animation Script v0.2 - Make your own on-screen animations for FSO
Visible Waypoints Script - Makes waypoints visible in-game
Run From File Script - Get around the pesky 31 character limit for script-eval

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: When When, When Every-Time
Okay, Edited my stickied tutorial with a link back here.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline FelixJim

  • 28
  • User 11092
Re: When When, When Every-Time
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).
In-Mission Techroom Script v0.4 - See information from the techroom in game
Simple Animation Script v0.2 - Make your own on-screen animations for FSO
Visible Waypoints Script - Makes waypoints visible in-game
Run From File Script - Get around the pesky 31 character limit for script-eval

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: When When, When Every-Time
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.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]