Author Topic: Questions about when-argument  (Read 7112 times)

0 Members and 1 Guest are viewing this topic.

Offline CommanderDJ

  • Software engineer
  • 210
Questions about when-argument
Dear HLP,
I've run into a bit of trouble with SEXPing here. Here's the situation: the player and a wingman are raiding a bunch of cargo containers guarded by sentry guns. There are nine cargo containers there, and the player must scan them. Containers 1 and 3 are crucial to the mission and must not be destroyed, whilst the others are expendable. I'm trying to FRED two events: one which checks if the player has scanned all the cargo (ie none of it is destroyed, which yields a bonus objective) and gives the directive "scan all cargo" . That's easy enough, and works fine. The other event only triggers if the first one is false, that is, if some of the cargo has been destroyed. I want this event to give the directive "scan remaining cargo", and to return true using a huge bunch of ands and ors when a) containers 2 and 4-9 are either destroyed or scanned and b) when containers 1 and 3 are scanned. Now the problem is not the event itself as I think I've FREDded it correctly. The problem is the little numbers next to directives. For the first event the directive initially reads "Scan all cargo [9]" and the number decreases as cargo is scanned. Now if any of the cargo is destroyed this directive becomes false (turns red) and the second directive "Scan remaining cargo" comes up. However, the number next to this second directive starts at 14! This is definitely not the number of cargo containers remaining. I assume this is because the system treats both branches of each or as one number. Now, I am almost 100% certain there is a much more efficient way of FREDding these events, (when-argument, maybe?), so if someone has either a solution to the number problem or a better way of FREDding it, then please share.
Thank you,
A Concerned FREDder

EDIT
Disclaimer: The reason I haven't used when-argument (if that's the way to go) is because I don't understand how it works. So if someone could explain, that would be awesome.


See latest post for current questions.
« Last Edit: November 08, 2010, 09:09:09 pm by CommanderDJ »
[16:57] <CommanderDJ> What prompted the decision to split WiH into acts?
[16:58] <battuta> it was long, we wanted to release something
[16:58] <battuta> it felt good to have a target to hit
[17:00] <RangerKarl> not sure if talking about strike mission, or jerking off
[17:00] <CommanderDJ> WUT
[17:00] <CommanderDJ> hahahahaha
[17:00] <battuta> hahahaha
[17:00] <RangerKarl> same thing really, if you think about it

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
When-argument is really easy.

It works exactly like a normal SEXP. Except.

Instead of specifying an exact ship in, say, 'is-destroyed-delay', you can say <argument> instead.

What you do is fill in the argument list (the thing that goes under every-of, or any-of, or whatever you pick, by hitting 'add data' a few times and manually typing in the arguments you want. For example, if you want 'is-destroyed-delay <argument>' to be true when Sathanas 1, 2 or 3, blows up, you would write:

when
any-of: Sathanas 1, Sathanas 2, Sathanas 3 (each as its own data entry)
is-destroyed-delay <argument>
thank-battuta

You could change the any-of to an every-of and it would become true (I believe) when all three have been destroyed.
Does that make sense?

 

Offline CommanderDJ

  • Software engineer
  • 210
Let me see if I understand you correctly.

So, using the cargo container example in my first post, say I wanted to FRED an event which checks if containers 2 and 4-9 have either been destroyed or scanned, I would use:
when-argument
every-of
Cargo 2
Cargo 4
...
Cargo 9

-or
--is-destroyed-delay
-----<argument>
--is-cargo-known-delay
-----<argument>

-do-stuff-here

Does that sound roughly right? Thanks for explaining, it makes a lot more sense now.

...and I've just thought of a complete restructuring of the mission in question, so the problems in the OP no longer apply. Thanks all.
[16:57] <CommanderDJ> What prompted the decision to split WiH into acts?
[16:58] <battuta> it was long, we wanted to release something
[16:58] <battuta> it felt good to have a target to hit
[17:00] <RangerKarl> not sure if talking about strike mission, or jerking off
[17:00] <CommanderDJ> WUT
[17:00] <CommanderDJ> hahahahaha
[17:00] <battuta> hahahaha
[17:00] <RangerKarl> same thing really, if you think about it

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Cargo scanning fun![SOLVED]
That would almost work, except that it could become true if, say, several of the containers were scanned but the rest destroyed - it wouldn't only satisfy with 100% scanned or 100% destroyed. If that's what you want, good.

 

Offline CommanderDJ

  • Software engineer
  • 210
Re: Cargo scanning fun![SOLVED]
That's exactly what I want. :D
[16:57] <CommanderDJ> What prompted the decision to split WiH into acts?
[16:58] <battuta> it was long, we wanted to release something
[16:58] <battuta> it felt good to have a target to hit
[17:00] <RangerKarl> not sure if talking about strike mission, or jerking off
[17:00] <CommanderDJ> WUT
[17:00] <CommanderDJ> hahahahaha
[17:00] <battuta> hahahaha
[17:00] <RangerKarl> same thing really, if you think about it

 

Offline CommanderDJ

  • Software engineer
  • 210
Re: Questions about when-argument
Question:
Say I have this:
when-argument
random-of Cargo 1, Cargo 2, Cargo 3, Cargo 4
has-arrived-delay Freighter
add-goal Freighter
ai-dock
<argument>
cargo dockpoint
cargo dockpoint
89

This gives Freighter a goal to dock with a random choice out of the 4 containers. However, if, say Cargo 1 is destroyed (or has been taken away by another transport) before Freighter arrives, will when-argument still consider it a valid option? At times I get my Freighter not doing anything after it warps in when one or more of the containers have been destroyed. Is this because when-argument is trying to get it to dock with a container that isn't there?
[16:57] <CommanderDJ> What prompted the decision to split WiH into acts?
[16:58] <battuta> it was long, we wanted to release something
[16:58] <battuta> it felt good to have a target to hit
[17:00] <RangerKarl> not sure if talking about strike mission, or jerking off
[17:00] <CommanderDJ> WUT
[17:00] <CommanderDJ> hahahahaha
[17:00] <battuta> hahahaha
[17:00] <RangerKarl> same thing really, if you think about it

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Questions about when-argument
Yes. You need to use invalidate-argument to remove the container from the argument list. This may get a little tricky.

 

Offline CommanderDJ

  • Software engineer
  • 210
Re: Questions about when-argument
So if I create another event that does this:

every-time-argument
any-of Cargo 1, Cargo 2, Cargo 3, Cargo 4
is-destroyed-delay <argument>
invalidate-argument <argument>

Would that work? I'll test it now.
[16:57] <CommanderDJ> What prompted the decision to split WiH into acts?
[16:58] <battuta> it was long, we wanted to release something
[16:58] <battuta> it felt good to have a target to hit
[17:00] <RangerKarl> not sure if talking about strike mission, or jerking off
[17:00] <CommanderDJ> WUT
[17:00] <CommanderDJ> hahahahaha
[17:00] <battuta> hahahaha
[17:00] <RangerKarl> same thing really, if you think about it

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Questions about when-argument
The question is not whether when-argument does, but rather whether ai-goal does this correctly. In this case, if a container is destroyed, no goal will be added (thus you get your freighter doing nothing).

What you should do is this:
Code: [Select]
( when-argument
(random-of
Cargo 1
Cargo 2
Cargo 3
Cargo 4
)
(and
(has-arrived-delay Freighter 0)
(not
(is-destroyed-delay <argument> 0)
)
(not
(=
1
@variable
)
)
)
(add-goal Freighter
ai-dock
<argument>
cargo dockpoint
cargo dockpoint
89
)
(modify-variable
@variable
1
)
)

With a repeat count of 2 or 3, and the variable set to 0 initially.

So if I create another event that does this:

every-time-argument
any-of Cargo 1, Cargo 2, Cargo 3, Cargo 4
is-destroyed-delay <argument>
invalidate-argument <argument>

Would that work? I'll test it now.

No, won't work, as argument lists are only valid in the sexp they're defined in.
« Last Edit: November 08, 2010, 09:23:09 pm by The E »
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Questions about when-argument
So if I create another event that does this:

every-time-argument
any-of Cargo 1, Cargo 2, Cargo 3, Cargo 4
is-destroyed-delay <argument>
invalidate-argument <argument>

Would that work? I'll test it now.

As The_E said, argument lists are only valid within a single event. Can't be passed between events without storing to a var.

The_E's example uses a very handy technique called (maybe?) a stop variable. I like them.

 

Offline CommanderDJ

  • Software engineer
  • 210
Re: Questions about when-argument
*solution*

Could you (or someone else) perhaps explain that solution? I don't think I understand what it does.
[16:57] <CommanderDJ> What prompted the decision to split WiH into acts?
[16:58] <battuta> it was long, we wanted to release something
[16:58] <battuta> it felt good to have a target to hit
[17:00] <RangerKarl> not sure if talking about strike mission, or jerking off
[17:00] <CommanderDJ> WUT
[17:00] <CommanderDJ> hahahahaha
[17:00] <battuta> hahahaha
[17:00] <RangerKarl> same thing really, if you think about it

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Questions about when-argument
It's going to pick randomly from the list of cargo items, and, so long as the cargo item selected has not been destroyed, it will order a dock with it. It will then set a var called 'variable' to 1, which prevents the SEXP from triggering again.

You'll note that if the cargo item picked has been destroyed it'll simply randomly select another argument.

You will want to use rand-multiple-of, though, and give the event a very high trigger count (I believe). Also an invalidate-all-arguments could be used instead of the var.

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Questions about when-argument
Well, basically, the problem is that if random-of chooses a cargo container that has been destroyed, ai-goal will simply exit without adding a new goal (as a freighter can't dock with something that doesn't exist).

The solution I posted simply runs the sexp until a valid target has been found using a variable to mark success.
Code: [Select]
(and
(has-arrived-delay Freighter 0)
(not
(is-destroyed-delay <argument> 0)
)
(not
(=
1
@variable
)
)

This is where the magic happens. This makes sure that the sexp only runs if
  • The Freighter has arrived
  • The Container chosen by random-of still exists
  • The Variable has a value != 1

Now, the actual event code is nothing special; the ai goal is assigned and (crucially), the check variable is set to 1 (thus ensuring that this sexp will not run again).

It's going to pick randomly from the list of cargo items, and, so long as the cargo item selected has not been destroyed, it will order a dock with it. It will then set a var called 'variable' to 1, which prevents the SEXP from triggering again.

You'll note that if the cargo item picked has been destroyed it'll simply randomly select another argument.

You will want to use rand-multiple-of, though, and give the event a very high trigger count (I believe). Also an invalidate-all-arguments could be used instead of the var.

Yes, but it doesn't make a difference, really.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Questions about when-argument
The invalidate-all-arguments doesn't (though it saves you a var slot and is slightly easier), but if you use rand-of instead of rand-multiple-of, won't it not work since it'll check the same argument every single time?

  

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Questions about when-argument
Yes, I believe so.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline CommanderDJ

  • Software engineer
  • 210
Re: Questions about when-argument
Thank you for your help so far!

I'm getting a slight problem. Basically, I'm using The_E's method for two Elysium transports (designated Transport 1 and 2), and I want each of them to pick up a random cargo container from a selection of six. Obviously the cargo container cannot be destroyed or be docked to the other transport. Transport 1 works fine, selecting a random one each time. Transport 2, however, does nothing each time I test it (it arrives after Transport 1 has departed). I've copied The_E's solution to the letter with three small modifications: there are six cargo containers instead of four, I'm using random-multiple-of rather than random-of as per General Battuta's suggestion, and the event checks both whether <argument> has been destroyed or has departed using an or statement rather just checking for destruction. The event has a repeat count of 6 and a trigger count of 99999 (also per Battuta's suggestion).

Any idea what I might be doing wrong here? If you want me to post the full event, I'll do so.
[16:57] <CommanderDJ> What prompted the decision to split WiH into acts?
[16:58] <battuta> it was long, we wanted to release something
[16:58] <battuta> it felt good to have a target to hit
[17:00] <RangerKarl> not sure if talking about strike mission, or jerking off
[17:00] <CommanderDJ> WUT
[17:00] <CommanderDJ> hahahahaha
[17:00] <battuta> hahahaha
[17:00] <RangerKarl> same thing really, if you think about it

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: Questions about when-argument
I did something that may relate to this in the third mission of DEM 1.5.  It ensured that a certain cargo was always in the very last container you scanned. :nervous:

I did something even more similar to this, complete with AI goals and docking, in the fourth mission of the Scroll demo, but that isn't released yet...

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Questions about when-argument
Thank you for your help so far!

I'm getting a slight problem. Basically, I'm using The_E's method for two Elysium transports (designated Transport 1 and 2), and I want each of them to pick up a random cargo container from a selection of six. Obviously the cargo container cannot be destroyed or be docked to the other transport. Transport 1 works fine, selecting a random one each time. Transport 2, however, does nothing each time I test it (it arrives after Transport 1 has departed). I've copied The_E's solution to the letter with three small modifications: there are six cargo containers instead of four, I'm using random-multiple-of rather than random-of as per General Battuta's suggestion, and the event checks both whether <argument> has been destroyed or has departed using an or statement rather just checking for destruction. The event has a repeat count of 6 and a trigger count of 99999 (also per Battuta's suggestion).

Any idea what I might be doing wrong here? If you want me to post the full event, I'll do so.

Well for one thing, take away the repeat count, it's useless here.

 

Offline CommanderDJ

  • Software engineer
  • 210
Re: Questions about when-argument
I thought that was necessary for the event to run more than once? Hmm, I obviously don't fully understand the solution I'm using.
[16:57] <CommanderDJ> What prompted the decision to split WiH into acts?
[16:58] <battuta> it was long, we wanted to release something
[16:58] <battuta> it felt good to have a target to hit
[17:00] <RangerKarl> not sure if talking about strike mission, or jerking off
[17:00] <CommanderDJ> WUT
[17:00] <CommanderDJ> hahahahaha
[17:00] <battuta> hahahaha
[17:00] <RangerKarl> same thing really, if you think about it

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Questions about when-argument
Trigger count and repeat count are another common point of confusion. Trigger count will alone do everything you need.

Trigger count says: 'This is the number of times the event can become true. It will become incomplete (and ready to trigger) again after it has become true.' Think of it as a semi-automatic gun; you're determining how many bullets there are in the clip but the trigger still needs to be pulled each time.

Repeat count says: 'Once the event becomes true, repeat its effects this number of times, at this fixed interval.' Think of it as a burst fire weapon that will fire X number of times each time the trigger is pulled once.
« Last Edit: November 08, 2010, 11:55:10 pm by General Battuta »