Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: Blitzerland on April 23, 2005, 10:22:54 am

Title: Quick FREDing question
Post by: Blitzerland on April 23, 2005, 10:22:54 am
This should be a fairly simple request, but I've been having trouble FREDing it.

I have six transports. If five survive, command sends a certain message. If three survive, another message. Less than that, another message.

I've been fiddling with this for awhile, and can't get it to work. Percent-ships destroyed doesn't work, neither does percent-ships departed, because it keeps calling multiple sexps.

*five ships survive sexp called*

Sexp called, but because five departed, it also implies that three departed.

*three ships survive sexp called*

Next I tried using this:

And
 
 -Percent-ships-destroyed-or-departed
 -100
 -(ship list)

 -Percent-ships-destroyed
 -50
 -(ship list)
 

Didn't work. Still calls muliple sexps. As soon as the "three ships departed" message plays, the "five ships departed" message follows it.
Title: Quick FREDing question
Post by: Blaise Russel on April 23, 2005, 10:30:55 am
Sounds like a job for variables!
Title: Quick FREDing question
Post by: karajorma on April 23, 2005, 10:31:12 am
Event 1
when
-and
-Conditions that make it time to check who survived
-percentage-ships-destroyed
-83
-send-message
--Only one ship survived


Event 2
when
-and
-Conditions that make it time to check who survived +1 second
-percentage-ships-destroyed
--50
-is-event-false
--Event 1
-send-message
--Only three ships survived

Event 3
when
-and
-Conditions that make it time to check who survived +2 seconds
-percentage-ships-destroyed
--0
-is-event-false
--Event 2
-send-message
--5 ships survived

That way the 3 ships survive event doesn't play if the 5 ships survived event is true.

If you're doing this in combat reverse the percentages and use percentage-ships-departed instead.
Title: Quick FREDing question
Post by: Nuclear1 on April 23, 2005, 10:33:00 am
Variables are your friend.

Make a new Variable in the Events section named "Safe Transports" or such. When each transport departs, use "modify-variable" and then add +1.

Set events:
-when
-SafeTransports
-=
-3

That's the cue for the "3 safe" message. To avoid confusion, use another variable for "ships destroyed", using a similar process as above. When the variable for "ships destroyed" equals 2, the "safe transports" variable will go off as if only 3 transports survived (which I assume you want).
Title: Quick FREDing question
Post by: karajorma on April 23, 2005, 10:43:05 am
Or you can use variable like the other two suggested :D
Title: Quick FREDing question
Post by: Blaise Russel on April 23, 2005, 10:51:07 am
But they're not quite as elegant as Kara's suggestion.

*suitably awed*
Title: Quick FREDing question
Post by: karajorma on April 23, 2005, 11:44:05 am
You're awed by that? I thought that a fairly simple suggestion.

This (http://www.hard-light.net/forums/index.php/topic,31462.0.html) is some of the stuff I'm more pleased with :D
Title: Quick FREDing question
Post by: Blaise Russel on April 23, 2005, 12:20:39 pm
Well, 'awe' may be hyperbole, but it's something that didn't occur to me at all, and I would have gone for a solution that uses three times as many events, so...
Title: Quick FREDing question
Post by: Hippo on April 23, 2005, 12:21:14 pm
Is it just me, or was almost this exact scenario covered int he walkthrough, except with docking transports?
Title: Quick FREDing question
Post by: Blitzerland on April 23, 2005, 01:14:03 pm
No, you looney.

Anyways, thanks for the help, all. I think I've got it now. :yes:
Title: Quick FREDing question
Post by: karajorma on April 23, 2005, 02:19:43 pm
Quote
Originally posted by Blaise Russel
Well, 'awe' may be hyperbole, but it's something that didn't occur to me at all, and I would have gone for a solution that uses three times as many events, so...


I do worry about that whenever I post a solution. FRED is getting so powerful these days that I wonder if I'm missing a really easy short cut somewhere :D
Title: Quick FREDing question
Post by: Night Hammer on April 23, 2005, 02:30:59 pm
id go with kara's suggestion, those variables creep me out:p
Title: Quick FREDing question
Post by: karajorma on April 23, 2005, 05:33:28 pm
I've never understood why variables scare so many people. I was using them in the first mission I ever made straight after doing the walkthrough :)

It was only when I got online and visited the VBB that I learned that variables were meant to be something I was supposed to be scared of for years :D
Title: Quick FREDing question
Post by: Hippo on April 23, 2005, 05:42:19 pm
I tend to avoid them, just of old habit... My first experience was when i put a space in a variabl name, and managed to destroy the mission...

I prefer to make long, drawn out events... I think for 2 reasons: One, because I enjoy thinking it through and making it work. And two, because i think its easier to debug. I'll compare the second statement to another situation: You are new to a campaign. You 'inherit' a half done mission from someone else. You have the plotline, but have to spend quite some time picking it apart, seeing how everthing was done, and either change your building style to use whats there, or redo everything to fit your standards. Most times its easier to just start over, and build it in a way that you know exactly whats going on. I choose to use long events, because that way i know exactly what is making things work, and often times, not work...

I'm pretty sure most people would use variables if they had to, but personal preference might make them avoid it...
Title: Quick FREDing question
Post by: karajorma on April 23, 2005, 06:00:49 pm
Thing is that there are several things that can only be done with variables.

Don't use them and you are imposing severe limits on what you can do with FRED (and those limits are getting larger as I think of new things I can do with them almost every time I open FRED)
Title: Quick FREDing question
Post by: Hippo on April 23, 2005, 06:06:06 pm
True, which is when i will use them. But 90% of the time, when there's something that can be done with a variable, it can be done with regular SEXP's... You also have to figure, that I like many others learned to FRED on FRED1, so its like giving someone an extra option, that they've already learned to live without in most cases.
Title: Quick FREDing question
Post by: Night Hammer on April 23, 2005, 06:08:09 pm
yeah ill use them if need be, but for the most aprt ill try another route
Title: Quick FREDing question
Post by: Trivial Psychic on April 23, 2005, 07:38:04 pm
I could condense it all down to one event, one variable, and one message, if the latest version of FSO is used.

variable = convoyships, default value of 0

message: convoy destroyed

"We've lost $convoyships of our transports!"

event name
-every-time-argument
--any-of
---Ship 1
---Ship 2
---Ship 3
--is-destroyed-delay
---< argument >
---0
--modify-variable
---convoyships(0)
---+
----convoyships(0)
----1
--send-message
---#command
---high
---convoy destroyed
Title: Quick FREDing question
Post by: karajorma on April 24, 2005, 03:27:15 am
True TP but there are two problems with that.

1) Due to a bug in the way messages are sent the message will just keep repeating ""We've lost 1 of our transports!". The variable $convoyships is resolved into a string the first time the message is used. From then on the string won't change no matter how many times you call it or change the underlying variable.
 Goober's aware of this bug and said he's trying to think of ways to solve it (If he hasn't already! :D )

2) The message would be rather repeatative. The methods suggested above would allow you to have a different message for each outcome.

That said it's a nice use of every-time-argument :yes:
Title: Quick FREDing question
Post by: Hippo on April 24, 2005, 06:41:24 am
yeah, combine that with send random message, and its really good :p
Title: Quick FREDing question
Post by: karajorma on April 24, 2005, 06:52:09 am
Good point. I hadn't thought of using send-random-message because I've never had any conditions where that that SEXP would be useful so I tend to forget it exists. :D

In this case once the bug with messages is fixed then it would probably be the best solution :D

*Suspects that my missions are going to see a proliferation of random messages now* :D
Title: Quick FREDing question
Post by: Hippo on April 24, 2005, 07:13:36 am
Actually, to make TP's even better, do this:

Code: [Select]
Event 1
-every-time-argument
--any-of
---Ship 1
---Ship 2
---Ship 3
--is-destroyed-delay
---< argument >
---0
--modify-variable
---convoyships(0)
---+
----convoyships(0)
----1
--do-nothing

Event 2 (chained)
+--and
|--not
|---is-event-true-delay
|----Event 5
|----0
+--is-destroyed-delay
|---Ship 1
|---1
+Send message
 |-#command
 |-Med
 |-Message

Event 3
+every-time
+--and
|--not
|---is-event-true-delay
|----Event 5
|----0
+---is-event-true-delay
|----Event 1
|----1
+---is-destroyed-delay
|-----Ship 2
|-----0
+-Send message
 |-#command
 |-Med
 |-Message

Event 4
+every-time
+--and
+--not
|----is-event-true-delay
|-----Event 1
|-----1
+---is-destroyed-delay
|-----Ship 3
|-----0
+-Send message
 |-#command
 |-Med
 |-Message

ad infinium
But wait! There's more!

Event 5
+when
|--=
|---Variable(0)
|---2
-+send-message
 |-#command
 |-[b]High[/b]
 |-2 freighters down message


So basically, each of the middle 3 events checks to see that the variable event (probably still there so that one can get debreifs done better) is true, and then checks to see that the events respective transport has been destroyed, BUT that the event triggered when 2 are destroyed is NOT true, so that the messages don't overlap, and sends the appropriate single ship message.

EDIT: the high and mediums are there, just so that should it backfire, you won't hear them at the same time...
Title: Quick FREDing question
Post by: karajorma on April 24, 2005, 08:51:09 am
Sorry hippo but I can't make head nor tail of that. If you want to really beef up TP's SEXP what I'd do is this.

Event 1
-every-time-argument
--any-of
---Ship 1
---Ship 2
---Ship 3
--is-destroyed-delay
---< argument >
---0
--modify-variable
---convoyships(0)
---+
----convoyships(0)
----1
--modify-variable
--RequestMessage(0)
--1

Event 2
every-time-argument
-m1
-m2
-m3
-m4
-m5
=
-RequestMessage(0)
-1
send-message
-#command
--medium
-< argument >
-invalidate-argument
--< argument >
modify-variable
-RequestMessage(0)
-0

Then you make 5 messages called m1 to m5 each of which goes something like this.

Alpha 1 you must cover those frighters better. We've already lost $convoyships of them

or

Freighter number $convoyships going down.


The above two events will give you a new message every time you lose a ship. No message will ever repeat and they'll appear in a different random order every time you play :D

BTW The best ideas from this post are going up in the FRED Cookbook as soon as this thread dies down. There's some very good stuff in here :D
Title: Re: Quick FREDing question
Post by: Singh on April 24, 2005, 09:00:48 am
Quote
Originally posted by Blitzerland
This should be a fairly simple request, but I've been having trouble FREDing it.

I have six transports. If five survive, command sends a certain message. If three survive, another message. Less than that, another message.

I've been fiddling with this for awhile, and can't get it to work. Percent-ships destroyed doesn't work, neither does percent-ships departed, because it keeps calling multiple sexps.

*five ships survive sexp called*

Sexp called, but because five departed, it also implies that three departed.

*three ships survive sexp called*

Next I tried using this:

And
 
 -Percent-ships-destroyed-or-departed
 -100
 -(ship list)

 -Percent-ships-destroyed
 -50
 -(ship list)
 

Didn't work. Still calls muliple sexps. As soon as the "three ships departed" message plays, the "five ships departed" message follows it.



Would this work?

-when
--and
----=
----percent-departed-delay
----(ship list)
----percentage for three ships
---<
----precent-departed-delay
----(ship list)
----percentage for five ships
-----sendmessage

-when
----=
----percent-departed-delay
----(ship list)
----percentage for five ships
-----send message

-when
---=
----precent-departed-delay
-----(ship list)
------100%
-------send message


?
Title: Quick FREDing question
Post by: Singh on April 24, 2005, 09:04:30 am
wait, actually that won't work.

Ach - never mind...my mind is playing tricks on me.
Title: Quick FREDing question
Post by: karajorma on April 24, 2005, 09:18:49 am
Actually it looks fine to me at a quick glance :D

It's actually pretty close to what I suggested doing at the bottom of my post.
Title: Quick FREDing question
Post by: Trivial Psychic on April 24, 2005, 07:56:37 pm
Now that I understand what a string-variable is, (and after reading your FRED Bugs thread Kara), I'd be nice to use the single envent every-time-argument line (once the bugs are fixed) so the message would include both the name of the ship going down, and the numer that have been lost.  Something like:

"The GTFr Nelson is going down!  That's 2 freighters we've lost so far."

Actually, it be better to have 3 variables within this event, 2 numerical and one string.  The string is changed to the content of < argument > when the event fires, and one numerical variable displays the number of ships lost, and the other calculates how many remain.  That way your early messages tell you you've lost 2 out of 6 transports, while later messages tell you you've only got 2 transports left.  If there was a way to perform calculations within a message there'd be no need for the 2nd variable, but that's what we've got.
Title: Quick FREDing question
Post by: karajorma on April 25, 2005, 04:10:53 am
Yeah. I'd been thinking about calculations in messages too. But for the moment I'd rather see what we have working. :D

I like the idea of having the name in the message too. Main thing that stopped me suggesting something along those lines is the bug we currently have regarding writing an argument to a string variable. The event I posted would actually work now.

Like the idea of having a couple of variables though. I'd probably work it so that each message had a combination of all three rather than all of them being used in every message to make it more realistic.
Title: Quick FREDing question
Post by: Cobra on April 25, 2005, 11:58:05 am
even though i've learned a little about what variables do, i still don't know how the hell to use 'em or when... that's why it scares me...
Title: Quick FREDing question
Post by: Trivial Psychic on April 25, 2005, 12:14:36 pm
Perhaps a few more events would be better.  Lets say that there are 6 convoy ships.  The first is the key every-time-argument event that performs changes to the variables.  Another would be keyed to fire when the ShipsDestroyed numeric variable = 1 so that a message is displayed saying that one ship is destroyed and what that ship name is using the string variable.  This singular event is useful because then you can say "ship" (the singular) after the first is destroyed, then additional events chained to the key event that include the plural "ships".  Furthermore, have the second event also keyed only to fire if the shipsdesroyed variable is between 1 (greater than) and 4 (less than) and include a send-message-random with various wordings of "XXX is destroyed!  That's Y ships we've lost so far".  Then another event keyed to fire when shipsdestroyed variable is between (greater than) 3 and (less than) 5, and another send-message-random with various wordings of "XXX is desrtoyed!  We've only got Z ships left", using the ShipsLeft numeric variable.  Then another event that only fires when shipsdestroyed is equal to 5 saying that "XXX is destroyed!  We've only got 1 ship left" so we can use the singular.  Then another event fires when shipsdestroyed = 6 saying that all convoy ships have been destroyed.

While I was typing this, I remembered that occasionally, there is an option to insert additional "when" conditionals within an event.  Perhaps some multiple when conditionals can be inserted within the master event so that we can condense all of the above into a single event.
Title: Quick FREDing question
Post by: Primus on April 25, 2005, 12:15:20 pm
@Cobra
The tutorial that comes with FS2 gives a good example. :)
Title: Quick FREDing question
Post by: Nuclear1 on April 25, 2005, 12:48:29 pm
*cough*Walkthrough, anyone?*cough*
Title: Quick FREDing question
Post by: Cobra on April 25, 2005, 12:50:53 pm
*ahem* yes, i've done the walkthrough, i've done about half of that mission, but i always get bored with it, and make something else. it's just that it doesn't give a halfways decent explanation of variables. (and yes, i read the new walkthrough karajorma made)
Title: Quick FREDing question
Post by: karajorma on April 25, 2005, 01:03:58 pm
I assume you're on about Darkage's or TopAce's. I haven't made my own walkthrough (Although maybe I should :D )
Title: Quick FREDing question
Post by: Hippo on April 25, 2005, 04:09:54 pm
Now i want to :nervous: :p

Oh, and incase you don't feel like drudging up the walkthrough on your computer, click here (www.woodentoyandgift.com/GTD/fred/).
Title: Quick FREDing question
Post by: karajorma on April 25, 2005, 04:48:09 pm
hmmm. I think I should add that to the FAQ. I've got the files available for download but sometimes you just want to check something quickly.