Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: TopAce on April 17, 2010, 09:53:08 am

Title: A SEXP tree doesn't work, but it should
Post by: TopAce on April 17, 2010, 09:53:08 am
I've got a mission which involves two Terran cruisers fighting each other at start. This fight gets interrupted by two Vasudan cruisers, and the warring Terran cruisers agree to a cease-fire and engage the Vasudans. They prevail, but the cruiser which comes out from the mission in a better shape will break the cease-fire and blow the other to bits.

I need two events for this: One that comes true if Cruiser #1 has more hitpoints left, the other if it's Cruiser #2. Then, through is-event-true-delay, some more events will come true that makes sure that the breaker of the cease-fire will eventually emerge victorious.

And here's the SEXP tree that should theoretically work, but it doesn't.
Code: [Select]
Cruiser 1 wins
-and
--is-destroyed-delay
---Vasudan cruisers
---0
-->
---hits-left
----Cruiser 1
---hits-left
----Cruiser 2

I figured out that (through temporarily making a directive to it) if I destroy my own cruiser (Cruiser 1), the event will return false. However, in every other scenario, it remains incomplete.

I also tried and-in-sequence, but it doesn't even display the directive.

Can anyone help?
Title: Re: A SEXP tree doesn't work, but it should
Post by: dragonsniper on April 17, 2010, 11:07:26 am
Would this by chance work...?

Code: [Select]
-and
--is-destroyed-delay
---Vasudan cruisers
----0
-and
-->
---hits-left
----Cruiser 1
-not
-->
---hits-left
----Cruiser 2

I'm looking at this one and am kinda doubting it, but maybe it'll work... unless it's not what you want at all.
Title: Re: A SEXP tree doesn't work, but it should
Post by: TopAce on April 17, 2010, 11:20:34 am
This one comes true no matter which cruiser emerges victorious.
Title: Re: A SEXP tree doesn't work, but it should
Post by: dragonsniper on April 17, 2010, 11:23:30 am
Is it possible that replacing the second "and" with an "or" instead might fix it?
Title: Re: A SEXP tree doesn't work, but it should
Post by: TopAce on April 17, 2010, 11:27:32 am
No, it doesn't.
Title: Re: A SEXP tree doesn't work, but it should
Post by: dragonsniper on April 17, 2010, 11:29:45 am
Ok. I'll take a look in FRED, and see if I can pull anything up...
Title: Re: A SEXP tree doesn't work, but it should
Post by: Shade on April 17, 2010, 11:30:06 am
Too tired to think straight at the moment, so I'm probably missing something important... but aren't you missing a 'when'?
Title: Re: A SEXP tree doesn't work, but it should
Post by: dragonsniper on April 17, 2010, 11:31:25 am
His when would obviously be at the beginning of it all... atleast I hope it is.
Title: Re: A SEXP tree doesn't work, but it should
Post by: TopAce on April 17, 2010, 11:34:15 am
It's there. I was assuming people take that for granted.
Title: Re: A SEXP tree doesn't work, but it should
Post by: dragonsniper on April 17, 2010, 11:42:04 am
What about this?

Code: [Select]
-and
--is-destroyed-delay
---Vasudan Cruisers
----0
-and
-->
---hits-left
----Cruiser 1
-----(hits left value)
-and
--<
---hits-left
----Cruiser 2
-----(hits left value)

Title: Re: A SEXP tree doesn't work, but it should
Post by: Shade on April 17, 2010, 11:43:16 am
With FRED, I never take anything for granted :p Accidentally replacing the when with something else is something I've done more than a few times.
Title: Re: A SEXP tree doesn't work, but it should
Post by: Rodo on April 17, 2010, 11:46:11 am
I don't understand what is not working, is it that you can't get your directive showing properly or that your cruisers do not engage each other?
Title: Re: A SEXP tree doesn't work, but it should
Post by: Shade on April 17, 2010, 11:52:13 am
Oh! I *was* missing something. You said you're using is-event-true-delay. Given that, it's quite possible that FRED is smart enough to say "Ok, so Cruiser 1's hits are lower than Cruiser 2's right now, but that may change later. Lets just trigger the event but leave it as incomplete in case he wants to play with it later". So, try using the conditions in this event as part of the triggers for the following event and cut out the is-event-true-delay, and see if that works.
Title: Re: A SEXP tree doesn't work, but it should
Post by: TopAce on April 17, 2010, 11:58:36 am
I had to use variables, but I got it working. Thanks for the tips, anyway. :yes:

I don't understand what is not working, is it that you can't get your directive showing properly or that your cruisers do not engage each other?

I needed directives to keep track of the events' states. If the event turns true, the directive turns true.
Title: Re: A SEXP tree doesn't work, but it should
Post by: Goober5000 on April 17, 2010, 01:16:08 pm
Keeping track of the event states is usually better done with messages.  It's generally a good idea to make directive events separate from logic events, unless the event is extremely simple.
Title: Re: A SEXP tree doesn't work, but it should
Post by: TopAce on April 17, 2010, 01:21:59 pm
I had a message, too.
Title: Re: A SEXP tree doesn't work, but it should
Post by: karajorma on April 17, 2010, 09:32:12 pm
The problem here is that if the ship is already destroyed hits-left won't return zero. Instead it returns SEXP_NAN_FOREVER i.e Not A Number.

You should include

-not
--is-destroyed
---Cruiser 1

-not
--is-destroyed
---Cruiser 2

to make the event work.
Title: Re: A SEXP tree doesn't work, but it should
Post by: Shade on April 17, 2010, 10:54:47 pm
Knowing you, you're probably almost certainly right, but even so l can't see how that can be the problem given that TopAce specified that none of the cruisers are destroyed at the time this event should run - Rather, the event is used to determine which is going to be destroyed later.

[Edit] Or do you mean the problem is that even after triggering, the event will remain as incomplete due to this? That actually wouldn't surprise me, although it isn't something I would have caught even when mostly awake.
Title: Re: A SEXP tree doesn't work, but it should
Post by: karajorma on April 18, 2010, 02:13:35 am
Ah, I misread the problem and thought the issue was if one of the cruisers was destroyed before the event can trigger.

In that case I'm also somewhat mystified as to why this isn't working.
Title: Re: A SEXP tree doesn't work, but it should
Post by: TopAce on April 18, 2010, 04:44:53 am
In that case I'm also somewhat mystified as to why this isn't working.

Me too. Logically, it should work. It's surprising that you need variables as a workaround, which work the same way in the event as hits-left.

And I also needed to use the + operator just to be able to use the variable. The "Replace Variable" option was greyed out. For reference, here's the tree that works now:

(http://img707.imageshack.us/img707/8350/cruisershull.jpg)

Mekhu is the Vasudan cruiser wing (2 ships), the friendly cruiser is the Privateer and the hostile Terran cruiser is the Edward. I also needed to take into consideration the outcome of both cruisers having the same hull percentage, hence the = operator.
Title: Re: A SEXP tree doesn't work, but it should
Post by: karajorma on April 18, 2010, 06:20:11 am
And I also needed to use the + operator just to be able to use the variable. The "Replace Variable" option was greyed out. For reference, here's the tree that works now:

(http://img707.imageshack.us/img707/8350/cruisershull.jpg)

WTF?

I'm going to make my own mission and test this out.


EDIT : Built a test mission and the SEXPs worked exactly as they should have. Directive comes true if you press F (to damage ship B) but nothing happens if you press T (To damage Ship A more). No idea what you're doing wrong, but unless there is more to your event than you're telling me the problem lies somewhere else.

BTW, I did spot a flaw in your mission design. Once you've sorted this problem out both events must include a check that the other one isn't true. Otherwise it's possible for both to come true.

[attachment deleted by admin]
Title: Re: A SEXP tree doesn't work, but it should
Post by: TopAce on April 19, 2010, 12:13:08 pm
I tested my mission thoroughly and it works perfectly well now. I don't know why the hits-left SEXP doesn't work as it should on my end, but variables do the trick, so I'll leave it as that.
Title: Re: A SEXP tree doesn't work, but it should
Post by: karajorma on April 19, 2010, 06:15:28 pm
I would strongly advise you back up your mission and make it work without them. Right now something is very wrong with your mission and instead of solving the problem you've hacked on a solution which seems to work.

I know FREDders in the community can build a mission but in general the debugging skills of the community suck. I also know as a non-coder you don't have access to the kind of debugging tools I have but hacks like this are the reason why I ran the last big FRED quiz. It isn't enough to hack a solution on and test to see if it works. If you don't know why your previous solution failed and why this one worked you don't know what might cause this one to fail either. You should never simply change things and test to see if that works unless you use that as more evidence to figure out what was wrong in the first place.
Title: Re: A SEXP tree doesn't work, but it should
Post by: Goober5000 on April 19, 2010, 11:31:34 pm
^--- win.