Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: karajorma on March 02, 2005, 04:44:39 pm

Title: How Do SEXPs Work Anyway?
Post by: karajorma on March 02, 2005, 04:44:39 pm
Well expect a lot of technical questions cause I'm FREDding again and this time I'm really stretching FS2_Open's new abilities :)

My problem is basically this. I have three events.

Event 1
Every-Time
-Whatever
-Modify Variable
--Mission Switch
--1

Event 2
-Every-Time
--=
---Mission Switch
---1
-Do Something
-Modify Variable
--Mission Switch
--0

Event 3
-Every-Time
--=
---Mission Switch
---1
-Do Something Else Cool
-Modify Variable
--Mission Switch
--0


Now obviously that's vastly over simplifying things but what I need to know is Will Event 2 always trigger and leave Event 3 untriggered? Will they both trigger? In which order if so?  

I tested it in my mission and it appears to be somewhat random. Then again there is so much going on there that I could be missing it. I suppose I could test this in FRED but then I'd have to check every time something like this came up so I'd appreciate a little more detail on what to expect.
Title: How Do SEXPs Work Anyway?
Post by: phreak on March 02, 2005, 05:02:41 pm
do you want 2 and 3 to be mutally exclusive or executed simultaneously?
Title: How Do SEXPs Work Anyway?
Post by: karajorma on March 02, 2005, 05:11:57 pm
Actually I have 8 or 9 events which trigger based on a variable and I want them all to trigger in a specific order.

If I know the order in which SEXPs trigger then it may be possible to have the mission work as is (In other words the bug I'm currently getting means that I've done something wrong).

Or it could be that the order can't be determine or can't easily be determined in which case I'll have to introduce a second control variable to make things work. I'd rather not do this though as I've already got enough variables in the mission without adding another one.



BTW While I'm here what exactly is the difference between every-time and When? I've noticed different behaviour depending on which is used but I'm not 100% on how they work.
Title: How Do SEXPs Work Anyway?
Post by: Goober5000 on March 02, 2005, 05:57:42 pm
Quote
Originally posted by karajorma
Actually I have 8 or 9 events which trigger based on a variable and I want them all to trigger in a specific order.
Can't you chain them?
Quote
Or it could be that the order can't be determine or can't easily be determined in which case I'll have to introduce a second control variable to make things work.
The events should be evaluated in the order they appear.  However every-time might produce emergent random behavior... :nervous:
Quote
BTW While I'm here what exactly is the difference between every-time and When? I've noticed different behaviour depending on which is used but I'm not 100% on how they work.
Every-time is just a when that flushes the sexp evaluation tree every time it's called.  The effect is that the event handler thinks the sexp has never been evaluated before, so it keeps checking it every frame.
Title: How Do SEXPs Work Anyway?
Post by: karajorma on March 02, 2005, 06:30:50 pm
Quote
Originally posted by Goober5000
Can't you chain them?


Sadly no. The trigger is not just the variable. The order which they need to be triggered in is dependant on other things. Sometimes event B will never have been triggered at all and I'll want Event C to go first. Sometimes B will have triggered lots of times and I'll then want C to go followed by B.

Told you I was pushing FRED hard :D

Besides unless I'm very much mistaken Chaining C to B would definately prevent C from ever executing. B would always be evaluated before C and change the value to 0 preventing C from triggering.

On top of that my experiences with chaining Key-Reset last Sunday has left me somewhat nervous about chaining two every-time events together. I was getting some seriously odd results from that. That's probably due to Key-Reset more than anything but still... :)  


Quote
Originally posted by Goober5000
The events should be evaluated in the order they appear.  However every-time might produce emergent random behavior... :nervous:


That's what I seem to be getting but the mission is pretty complicated so I can't be 100% certain that it wasn't just me f**king up somewhere else. I think I'm going to have to introduce another variable to keep track of which order to execute in. That shouldn't be that difficult to do but I wanted to check it was needed before I added another layer of complexity to the mission.

Quote
Originally posted by Goober5000
Every-time is just a when that flushes the sexp evaluation tree every time it's called.  The effect is that the event handler thinks the sexp has never been evaluated before, so it keeps checking it every frame.


Now how is that different from When with a high repeat and a delay of 0?

I've been assuming the difference is this.

I have event A. Event B checks if Event A is true as part of it's trigger.

With When as soon as the event triggers once (either true or false) Event B is stuck with whatever the outcome was. If A evaulates to false then B will never trigger even if in one of the later repeats A becomes true.

With Every-time Event A is checked every time to see if it is true or false.

Did I get it right?
Title: How Do SEXPs Work Anyway?
Post by: Goober5000 on March 02, 2005, 07:12:40 pm
No, but that's because your assumption is flawed.  The sexp system is a bit more tricky than that.

If you evaluate an event at the beginning of a mission, it returns "incomplete".  Eventually the event becomes either true or false, at which point it executes its action.

However the event is (usually) locked once it's no longer incomplete.  So once it's true it stays true, and the same with false.  (I say "usually" because there are certain sexps that aren't locked.)

Now if the event has a repeat count, then as soon as it becomes true it will start repeating, whether it's been locked or not.  Not only that, but it will continue repeating even if the sexp becomes false in the meantime.

With every-time, the sexp flushes its "memory" after every evaluation, which means it's never locked true or locked false.  Whether it executes its action is entirely dependent upon its condition.

So your Event B works as described, but your understanding of Event A was incorrect.

As for your experiences with key-reset, that's likely due to every-time more than anything else.  I'd be wary of using every-time with either a repeat count or a chain.
Title: How Do SEXPs Work Anyway?
Post by: karajorma on March 03, 2005, 07:23:25 am
Aha. Think I've got a handle on it now :) Actually I think I had a handle on it when it came out and then forgot how it worked cause I've barely touched FRED (except for looking at other peoples missions) in the last 6 months or so.

The problem with Key-reset was actually with Key-Reset itself. It caused odd behaviour with repeating events even back in Retail. Strangely enough using every-time is in fact the only way I could determine to actually get key-reset to work properly. (As long as I was not using keys 1-4 which for some reason the game treats differently).

Time to add another variable or two then :) I'm right in thinking that the maximum is 100 right? (Not that I'm anywhere close to that!)
Title: How Do SEXPs Work Anyway?
Post by: Goober5000 on March 03, 2005, 11:25:01 am
Yep.