Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: Legate Damar on April 23, 2012, 10:22:34 pm

Title: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 23, 2012, 10:22:34 pm
It's rather embarrasing that I can't remember how to do this, as it seems so simple, but:

If I want an event to return true when a ship is destroyed, but only after another event, how would this be accomplished?

For example, if I want Event A to return true when Ship A is destroyed, but only after Ship B arrives. So if Ship A is destroyed before Ship B arrives, the event will never return true.

What is the proper way to implement this?
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 23, 2012, 10:32:18 pm
when > and > is-destroyed-delay & is-event-true-delay

Or for your specific example...

when > and > is-destroyed-delay & has-arrived-delay
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 23, 2012, 10:38:12 pm
Yes, I considered that, but I thought that would check to see if the ship was destroyed any time in the mission, so if Ship A is destroyed before Ship B arrives, it would return true as soon as Ship B arrives, which I don't want.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: General Battuta on April 23, 2012, 10:40:05 pm
You should use and-in-sequence!
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 23, 2012, 10:47:35 pm
Oh, of course!  :banghead:

I knew I was missing something simple.

One mor question: How would I check for any ship of a certain team to be destroyed? For example, make an event return true when any hostile or friendly ship is destroyed.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: General Battuta on April 23, 2012, 10:50:13 pm
When-argument is one way to do that.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 23, 2012, 10:50:26 pm
Derp, sorry I misread your issue, but Battuta gave you a good solution.

As for the next one, I suggest reading this tutorial (http://www.hard-light.net/wiki/index.php/Tutorial_-_Conditional_Arguments) and using 'Any Of' argment sexps or something like that.

Ninja'd

But my response gets a gold star for including the link to a good tutorial!
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Droid803 on April 23, 2012, 11:02:45 pm
percent-ships-destroyed can also do that (make the percent it check correspond to one, two, or three etc).
That is, if you don't care about which ones at all.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 23, 2012, 11:12:40 pm
Thank you. I think I've got it now.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 24, 2012, 12:00:28 am
Hmm, I thought it was going to work, but my event is not working correctly. I have taken a screenshot (censored for spoilers), can anyone see what is wrong with it?

(http://i39.tinypic.com/x1zmf8.jpg)

Additional information: The 2-5th censored spoilers are wing names. The total amount of ships in all waves of the three wings listed in the percent-ships-destroyed expression is 20.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 24, 2012, 12:09:09 am
From how this looks, this will NOT mark true if any one of those ships (that are in the percent sexp) are destroyed before the other ship has arrived.

In other words, all ships (this would be so much easier to discuss without all those frakking censors.. I'm already sick of trying to explain which ship I'm talking about) must not be destroyed before the arrival sexp is true. If that is the intended purpose then your next step is to debug to make sure that is precisely what is happening.

My other guess is that using wings in the percent-ships-destroyed sexp may not work like you expect, but I'm not 100% sure on this.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 24, 2012, 12:18:36 am
I'm sorry. Is this better?

(http://i42.tinypic.com/eaik9e.jpg)

What I want is for it to return true when any ship in wing 2, 3, or 4 is destroyed after wing 1 arrives, even if any ships in wings 2, 3, or 4 have been destroyed previously.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Droid803 on April 24, 2012, 12:27:43 am
oh that won't work.
it will be FALSE FOREVER if any ship in wing 2, 3, or 4 die before wing 1 arrives.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 24, 2012, 12:28:33 am
So how do I get it to work?
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 24, 2012, 12:43:40 am
So, you have 3 wings of fighters in the mission. Then you have Wing 1 arriving... and you want this event to become true when any ship of Wings 2,3,4 are destroyed after Wing 1 arrives. However, it is possible for Wings 2,3,4 to have ships destroyed before Wing 1 arrives?

Well first up this sounds like a good setup for a broken mission. What happens if the player destroys all the fighters in Wings 2,3,4 before Wing 1 arrives?

But a possible solution might be an any-of argument list. Something like this perhaps...

When-argument
>Any-Of
>>List of ships
>Is-Destroyed-Delay
>>Ship <Argument>
>>Delay
>Invalidate-Argument
>>Ship <Argument>
>When
>>Has-Arrived-Delay
>>>Ship
>>>Delay
>>ACTIONS TO TAKE

This is untested and I just came up with it on the spot. The idea is that when any ship is destroyed it is removed from the list (invalidate argument) of ships that can be destroyed after Wing 1 has arrived. However, if a ship is destroyed and has-arrived-delay tests true, then more actions will take place.

EDIT: You'll need to give this a trigger count equal or greater than the number of possible ships there are to be destroyed.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 24, 2012, 12:50:15 am
So, you have 3 wings of fighters in the mission. Then you have Wing 1 arriving... and you want this event to become true when any ship of Wings 2,3,4 are destroyed after Wing 1 arrives. However, it is possible for Wings 2,3,4 to have ships destroyed before Wing 1 arrives?

Well first up this sounds like a good setup for a broken mission. What happens if the player destroys all the fighters in Wings 2,3,4 before Wing 1 arrives?

This event is not essential to the mission. It just sends an optional message with no critical information. Still I don't want to just remove it.

Quote
But a possible solution might be an any-of argument list. Something like this perhaps...

When-argument
>Any-Of
>>List of ships
>Is-Destroyed-Delay
>>Ship <Argument>
>>Delay
>Invalidate-Argument
>>Ship <Argument>
>When
>>Has-Arrived-Delay
>>>Ship
>>>Delay
>>ACTIONS TO TAKE

This is untested and I just came up with it on the spot. The idea is that when any ship is destroyed it is removed from the list (invalidate argument) of ships that can be destroyed after Wing 1 has arrived. However, if a ship is destroyed and has-arrived-delay tests true, then more actions will take place.

EDIT: You'll need to give this a trigger count equal or greater than the number of possible ships there are to be destroyed.

Okay. It should be mentioned that wings 2, 3, and 4 have multiple waves, so from the way I understand arguments work, I should just type the names of all of the ships in all of the waves (as in, 1 2 3 4 for the first wave, and 5 6 7 8 for the second)?
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 24, 2012, 01:40:27 am
I implemented your suggested sexp and it seemed to work, except that messages 1 and 2 were both sent twice, and immediately afterward they were both sent twice again. I added an invalidate-argument to the end of the sexp, but it only removed one set of double messages - messages 1 and 2 were still both sent twice.

How would I proceed now?
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Snail on April 24, 2012, 07:13:53 am
How about adding a chained event after the first one? Would that work?

:nervous:
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 24, 2012, 07:20:10 am
You mean take everything after this part:

When-argument
>Any-Of
>>List of ships
>Is-Destroyed-Delay
>>Ship <Argument>
>>Delay
>Invalidate-Argument
>>Ship <Argument>

And then add a new (chained) event:

>When
>>Has-Arrived-Delay
>>>Ship
>>>Delay
>>ACTIONS TO TAKE

I will try that, if that is what you mean.

Also I have been making a lot of progress with this mission!
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Snail on April 24, 2012, 08:19:39 am
Well what I meant was have all the conditions in one (repeating) event and then have the messages in a separate (non-repeating) event chained to the first one.


EDIT

Okay I actually hadn't read the thread at all when I posted that

Having read the thread, I don't see why this wouldn't work

+when-argument
++(list of ships)
+and-in-sequence
++has-arrived-delay
+++delay
+++Wing 1
++is-destroyed-delay
+++delay
+++<argument>
++(actions)
++invalidate-argument
+++<argument>

But I am **** at logic and sexps anyway so blergh
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 24, 2012, 08:32:06 am
If I understand your issue correctly, then you really only need this event to actually become true once.. which is a derp on me. Add an invalidate-all-arguments sexp like this.

When-argument
>Any-Of
>>List of ships
>Is-Destroyed-Delay
>>Ship <Argument>
>>Delay
>Invalidate-Argument
>>Ship <Argument>
>When
>>Has-Arrived-Delay
>>>Ship
>>>Delay
>>ACTIONS TO TAKE
>>Invalidate-all-arguments

Be sure it is nested in the second 'when' or it will stop the whole sexp before it can be marked true. If you still have a few repeats, then consider raising your trigger delay by a second or two.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 24, 2012, 09:01:08 am
I will try that, thank you
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 25, 2012, 12:39:21 am
This version seems to be working correctly, thank you!

With that, the FREDding of my demo mission is all but complete. Still need to do some other work, though, before I can release it.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: karajorma on April 25, 2012, 12:46:00 am
I'd strongly recommend reading this (http://homepage.ntlworld.com/karajorma/FAQ/fredcommonmistakes.html) before you release it.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Snail on April 25, 2012, 12:57:01 am
Well now that it's all sorted, could someone just give me a heads up as to what was wrong with this one?
+when-argument
++(list of ships)
+and-in-sequence
++has-arrived-delay
+++delay
+++Wing 1
++is-destroyed-delay
+++delay
+++<argument>
++(actions)
++invalidate-argument
+++<argument>
Just to know what I've done wrong... At this point it's like I've been fredding for ages but I still suck arse. Makes me sad.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 25, 2012, 02:09:28 am
Probably because you didn't use invalidate all arguments
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 25, 2012, 02:47:45 am
I'd strongly recommend reading this (http://homepage.ntlworld.com/karajorma/FAQ/fredcommonmistakes.html) before you release it.

My spelling and grammar in the mission is good, I do not always pay attention to that when I am writing stuff online but writing the mission I tried to make it done well.

I have not made a background yet, I am planning to do that later.

I put ships on the Y axis.

My directives and mission objectives work, I have tested them.

I put a ship on the escort list. The mission really only needs one ship on it.

I named my events and messages logically.

The return to base thing works in all the situations I tested (I think I tested them all).

I don't think there is a way to break the mission but I might be wrong, I cannot think of everything.

I have done and tested all of the debriefings.

I named the ships correctly.

I have delays between waves and randomization of delay.

It is a scramble mission so loadouts are preselected.

I was having some trouble getting my warp out too early debriefing to work but it is working now.

Of the stuff I still have to do, I think about 50% is things I know how to do myself... otherwise I will ask. Mostly modding stuff.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: karajorma on April 25, 2012, 03:13:41 am
Well now that it's all sorted, could someone just give me a heads up as to what was wrong with this one?

I lost track of what you all were trying to achieve about 10 posts ago. If you summarise what it was supposed to do, I'll tell you why it didn't.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Snail on April 25, 2012, 05:31:29 am
It was supposed to send a message when any one of some ships was destroyed but only after another ship had arrived. Or something.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: karajorma on April 25, 2012, 07:15:46 am
In that case I can't see any reason why it wouldn't work.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 25, 2012, 08:06:05 am
looks like it should work. and-in-sequence has just been unreliable for me in the past, so I tend to forget about it.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: karajorma on April 25, 2012, 08:17:12 am
looks like it should work. and-in-sequence has just been unreliable for me in the past, so I tend to forget about it.

That's the exact kind of superstition I keep trying to stamp out. As far as I know there are no bugs in the and-in-sequence SEXP. It's just people misunderstanding how to use it.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: TopAce on April 25, 2012, 08:25:52 am
Snail: please don't be offended if I ask the obvious, but you are using "any-of," right? And you have double-checked that all arguments are spelled correctly? Also I think an actual screenshot of the event in FRED would be more useful.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 25, 2012, 08:36:58 am
looks like it should work. and-in-sequence has just been unreliable for me in the past, so I tend to forget about it.

That's the exact kind of superstition I keep trying to stamp out. As far as I know there are no bugs in the and-in-sequence SEXP. It's just people misunderstanding how to use it.

Then care to explain it? Because I'm pretty sure I understand it. I mean, it's not a very hard concept... Perhaps it's because I just got up and I'm a bit touchy, but I don't like you calling me "superstitious". I've had the SEXP fail on me for whatever reason in the past so I simply choose another way to do the same thing. There's no "right" way to FRED....

Snail: please don't be offended if I ask the obvious, but you are using "any-of," right? And you have double-checked that all arguments are spelled correctly? Also I think an actual screenshot of the event in FRED would be more useful.

Snail never actually wrote the SEXP in FRED. He was just trying to understand why his proposed solution would or wouldn't work and thus has no screenshot for you...
Title: Re: Evaluating ships destroyed only after a certain event
Post by: TopAce on April 25, 2012, 08:59:56 am
looks like it should work. and-in-sequence has just been unreliable for me in the past, so I tend to forget about it.

That's the exact kind of superstition I keep trying to stamp out. As far as I know there are no bugs in the and-in-sequence SEXP. It's just people misunderstanding how to use it.

Then care to explain it? Because I'm pretty sure I understand it. I mean, it's not a very hard concept... Perhaps it's because I just got up and I'm a bit touchy, but I don't like you calling me "superstitious". I've had the SEXP fail on me for whatever reason in the past so I simply choose another way to do the same thing. There's no "right" way to FRED....

I'm gonna ninja this.

And-in-sequence turns FALSE if the events in it turn true in the wrong order.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 25, 2012, 09:54:58 am
Well apparently my understanding of that simple concept, but distaste for the sexp itself is "superstition".

Clearly the fact that so many people 'misunderstand' that SEXP means there is more to it than the order in which arguments test true, and I would like Karajorma to explain them rather than simply saying "nope, you've got it wrong and don't understand".
Title: Re: Evaluating ships destroyed only after a certain event
Post by: karajorma on April 25, 2012, 10:47:09 am
Then care to explain it? Because I'm pretty sure I understand it. I mean, it's not a very hard concept... Perhaps it's because I just got up and I'm a bit touchy, but I don't like you calling me "superstitious". I've had the SEXP fail on me for whatever reason in the past so I simply choose another way to do the same thing. There's no "right" way to FRED....

I explained the term superstition in the FRED Quiz thread but I'll repost it here (reminds me, I must post more questions at some point!).

Quote
The purpose of these tests is for users to exercise their debugging skills.

[ SNIP ]

I'm sure each one of us can name an occasion where an event we thought would work hasn't and we've simply tinkered with it a little until it did, never understanding why it failed the first time but works now. A coding book I once read referred to this practice as superstition and in many ways that's especially apt when it comes to FRED. When a problem occurs with a mission in FRED, it's better to figure out why the mission isn't working than to simply change SEXPs and test until it starts working again. You may either prevent similar mistakes in the future, or discover how to better use a feature and get great ideas how to use it.


Now do you see why I use the word? It's not that I'm calling you superstitious, I'm saying that SEXPs can quickly build up superstitions around them. and-in-sequence is actually the number 1 contender for this. There are many FREDders like you who choose not to use a perfectly good SEXP which does exactly what it says it does because it has failed for reasons they don't understand.

In my opinion, this is the point where you can tell the excellent FREDders from the merely good ones. The best FREDders want to know why the SEXP failed. Everyone else simply solves the problem a different way and moves on. When I say I'm trying to stamp out superstitions, I mean I'm trying to move more FREDders into the excellent FREDder category. I want people to look at failures in a particular event as a chance to learn, not just an obstacle to go round. Too many FREDders simply fix the problem and then are equally clueless next time a similar event breaks.

Clearly the fact that so many people 'misunderstand' that SEXP means there is more to it than the order in which arguments test true, and I would like Karajorma to explain them rather than simply saying "nope, you've got it wrong and don't understand".

I can't tell you why your events didn't work without an example. But have a look at this question (http://www.hard-light.net/forums/index.php?topic=55631.msg1128015#msg1128015) in the first FRED Quiz I ran and see if you can figure out why it's not working. Mistakes like the one in this question are the biggest cause of failure for the and-in-sequence SEXP.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 25, 2012, 11:03:27 am
Thank you. That's just straight up belittling...

You talk like and-in-sequence is this mystifying SEXP that stumps all but the bestest of the best FREDers and point me to your 'easy' question to see if I have the know-how to figure it out. I was really trying not to let this get under my skin, but I'm kinda done with your high horse attitude about this particular SEXP.

It makes sense when you go off on these tangents about everytime SEXPs because most people do use them incorrectly. This one, though, is very straightforward.. please stop talking to me like I'm some sort of idiot that can't figure out when SEXPs turn true and in which order...
Title: Re: Evaluating ships destroyed only after a certain event
Post by: TopAce on April 25, 2012, 11:08:50 am
Quote
The best FREDders want to know why the SEXP failed. Everyone else simply solves the problem a different way and moves on.

Only the FREDders who happen to be coders as well can look at the SEXP's code and see for themselves how exactly it works. The lesser ones have two options: a) ask, b) experiment and try to figure it out for himself. If you choose a) you risk receiving the conclusions of those who chose b). Since b)'s conclusions are possibly flawed and inaccurate, and a) has no choice but to listen to b), superstitions start spreading.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: karajorma on April 25, 2012, 11:48:28 am
Oh I know why these superstitions get started. That's why when someone posts something like mjn.mixael did, I point out the other side of the argument. The quality of FREDding has improved over the years, but I've been around long enough to remember when people flat out told people not to use and-in-sequence because it never worked properly.

Thank you. That's just straight up belittling...

You talk like and-in-sequence is this mystifying SEXP that stumps all but the bestest of the best FREDers and point me to your 'easy' question to see if I have the know-how to figure it out. I was really trying not to let this get under my skin, but I'm kinda done with your high horse attitude about this particular SEXP.

No, I'm not attempting to belittle you. Quite frankly I'm not sure what you're getting so annoyed about. You're claiming that you understand perfectly well how and-in-sequence works AND claiming that in the past it has failed for some unknown reason you feel is a big enough issue that it prevents you using the SEXP now. Surely you can see that those two statements don't fit together?
 If in the past it failed because you were still a beginning FREDder then there is no reason not to use it now. Otherwise it suggests you don't feel confident that if you use it this time, it won't work again for some reason you don't understand. If you do understand why it didn't work in the past, and do feel confident it will work next time you try to use it, why you wouldn't use the simplest solution to a problem?

And I never said that and-in-sequence is hard to use. I consider it to be exceedingly simple. I'm constantly surprised people have any trouble with it because it is exceedingly simple once you get past a couple of minor gotchas. So again, I'm confused about why someone would say they don't use the SEXP. Especially when the alternative is to create a new event. Close the event editor window. Open it again. And then make an event referencing the first one. Seriously, if you can tell me why you'd do that, I'm all ears. Cause I can't see a sensible reason for doing it.  :confused:

When I was talking about the difference between the best FREDders and the rest, I wasn't saying that only the best FREDders use and-in-sequence or some nonsense like that. I was talking in general about an attitude of always trying to figure out why a SEXP didn't work. As I keep saying, there is a tendency to forget about that and simply fix the problem in another way. It's not a good habit to develop.

Quote
It makes sense when you go off on these tangents about everytime SEXPs because most people do use them incorrectly. This one, though, is very straightforward.. please stop talking to me like I'm some sort of idiot that can't figure out when SEXPs turn true and in which order...

I linked to the easiest example of why and-in-sequence can fail. You probably encountered a more complex version but in the end the root cause is the same, you've misunderstood how to use the SEXP. Now that's probably justifiable and understandable. But that doesn't mean that it's a state of affairs you should willingly continue. If the SEXP is as simple as you claim, why not use it?
Title: Re: Evaluating ships destroyed only after a certain event
Post by: mjn.mixael on April 25, 2012, 01:14:51 pm
Quite simple really.. why do you insist that I use a SEXP I don't prefer (regardless of if the time it didn't seem to work was when I first started FREDing) when it took me a minute to create an alternative event that performed the same thing?

It didn't seem to work for me however long ago and so I figured out alternative methods to do the same thing. That's the method that I've stuck with since, just because I can. I don't need to FRED the way you say I should FRED just because you perceive misunderstanding.
Title: Re: Evaluating ships destroyed only after a certain event
Post by: Legate Damar on April 25, 2012, 04:30:04 pm
Please don't fight in my thread
Title: Re: Evaluating ships destroyed only after a certain event
Post by: karajorma on April 25, 2012, 06:15:55 pm
Hell, I'm not even fighting. I'm going over good FREDding practice. Admittedly I might have been a bit abrasive in the way I did it, but unlike you and mjn.mixael I was in the community during the bad old days when people would flat out tell you nonsense about how to use certain SEXPs. That's died off somewhat cause with the source code, it's easy to check what's going on.

Quite simple really.. why do you insist that I use a SEXP I don't prefer (regardless of if the time it didn't seem to work was when I first started FREDing) when it took me a minute to create an alternative event that performed the same thing?

It didn't seem to work for me however long ago and so I figured out alternative methods to do the same thing. That's the method that I've stuck with since, just because I can. I don't need to FRED the way you say I should FRED just because you perceive misunderstanding.

You can FRED however you want. You can use whatever SEXPs you want. If you want to eschew using distance in favour of distance-ship-subsystem, I'm still not going to stop you.

 I just don't want people using sub-optimal SEXPs because they don't understand how to use better ones. If you're saying it's a deliberate choice, fine. But notice that your first post doesn't say that. It simply says you don't use it cause it didn't work in the past for you. You never mentioned that you've since figured out why. Nor did your first couple of follow up posts.


As for why I feel it is important to make the and-in-sequence SEXP work. Well I've never tried this but


when-argument
-any-of
-<list of ships>
and-in-sequence
- >
--distance
---<argument>
---GTD Cathage
--2000
- is-destroyed-delay
--0
--GTCv Dashor
-Do something to
--<argument>
-Send-message
--Ha! You got to close to the Carthage before the Dashor was destroyed! You have the space plague now!


Now it's 7am and I'm not certain that would work. But if it does, there's an example of something that would be a royal pain in the arse to do without using and-in-sequence. That said, I've got my reasons for suspecting why it might not work and if I'm right, I've uncovered why Snail's event didn't work either.

Since I am an excellent FREDder, unless someone tells me whether that works or not in the next few hours, I'm going to try it out when I get home from work. Cause coming up with problems like this and trying them out is why I'm an excellent FREDder.