Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: General Battuta on October 30, 2010, 12:51:33 pm

Title: Interesting discovery
Post by: General Battuta on October 30, 2010, 12:51:33 pm
Axem and I figured something interesting out about the engine today.

Let's say you're using a when-argument to track how many ships from Beta wing have arrived in the battle.

EVERY-TIME-ARGUMENT (just using an every-time here for neatness, trigger count high with interval 0 works too)
any-of
Beta 1
Beta 2
Beta 3
Beta 4
Beta 5
Beta 6
has-arrived-delay 0, <argument>
modify variable (numBeta), (numBeta) + 1
invalidate-argument

You'd expect this variable to go from 0 to 6 when Beta wing arrives, right?

WRONG

It will go to 1. The engine does not count the individual arrival of ships in a wing; it simply checks whether the wing has arrived.

Funny stuff.

edit: also totally wrong, see below  :cool:
Title: Re: Interesting discovery
Post by: Scourge of Ages on October 30, 2010, 01:08:18 pm
Interesting. Not entirely unexpected however.

What happens if you make 6 events, one for every member of Beta wing? Or you could just check if Beta wing arrives and +6 to the variable.
Title: Re: Interesting discovery
Post by: FUBAR-BDHR on October 30, 2010, 01:20:16 pm
Actually your description of what is happening is off.  It does count each individual ship; however, since they all arrive in the same frame the variable is only incremented once.  This is one of the reasons for the do-for-valid-arguments sexp. 
Title: Re: Interesting discovery
Post by: General Battuta on October 30, 2010, 01:33:20 pm
Actually your description of what is happening is off.  It does count each individual ship; however, since they all arrive in the same frame the variable is only incremented once.

Are you sure? We discussed this as a possibility but because these type of event can normally handle things that at least seem to happen in the same frame we thought it unlikely.

I could be wrong though.
Title: Re: Interesting discovery
Post by: FUBAR-BDHR on October 30, 2010, 01:40:21 pm
Any-of, every-of,etc only do things once unless they contain <argument> in which case every item that becomes true that frame is processed.  So if you do say

any-of
<list>
has-arrived-delay
<argument>
change-iff
traitor
<argument>
send-message
chg to traitor

it will change all 6 ships to traitor but only send one message.  Same with the modify variable in your example.
Title: Re: Interesting discovery
Post by: General Battuta on October 30, 2010, 01:43:56 pm
Also interesting. So everything that happens in one frame is treated as a single...thing? Whatever you're counting?
Title: Re: Interesting discovery
Post by: FUBAR-BDHR on October 30, 2010, 01:47:15 pm
I wouldn't say everything.  There are always exceptions.  Can't think of one at the moment.
Title: Re: Interesting discovery
Post by: karajorma on October 30, 2010, 06:34:58 pm
FUBAR's got the handle on the cause of this one.

The other thing to remember with the argument SEXPs is the order they work in. If all 6 ships have arrived you would expect any SEXP containing <argument> to happen 6 times and you'd be right. What you might not expect is that if you have this

change-iff
-<argument>
-Hostile
Modify-variable
-StringVariable[None]
-<argument>

what will happen is that all 6 ships will have their iffs modified and then modify-variable will be called 6 times in a row ending up with the name of the last ship on the list. So if later in the event you have this

self-destruct
-StringVariable[None]

You wouldn't blow up all six ships. You'd self destruct the 6th one 6 times. :D
Title: Re: Interesting discovery
Post by: Mobius on October 31, 2010, 05:55:23 am
I've experienced something similar to this a few days ago, but in a completely different scenario. I had to switch to plan B. :)
Title: Re: Interesting discovery
Post by: Scotty on November 02, 2010, 09:44:30 am
Thanks in part to this thread, and also in part due to Battuta, I can now use variables in a rudimentary fashion. :D