Author Topic: How do I invalidate arguments for ships that have left the mission?  (Read 1315 times)

0 Members and 1 Guest are viewing this topic.

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
How do I invalidate arguments for ships that have left the mission?
I've got an event.

I want it to look at ships on an argument list. I want it to pick out ships that are still in the mission. I want it to check those ships' class, and, depending on the class, run a series of sexps on them.

How can I do this without resorting to LUA?

Spoiler:
it's apparently much, much more difficult than you'd imagine?

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: How do I invalidate arguments for ships that have left the mission?
Unless I'm missing something obvious here, the problem is that every means I can find to detect that a ship is not in the mission will - once it finds a ship not in the mission - declare that ALL SUBSEQUENT SHIPS on the argument list are also not in the mission, ruining everything forever.

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: How do I invalidate arguments for ships that have left the mission?
Turns out that this problem will not occur as long as you are checking the argument ships for departure in the PARENT conditional (the outermost in any group of nested conditionals). That one is flushed properly, but nested conditionals are not.

This is all very cursed

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: How do I invalidate arguments for ships that have left the mission?
Can you post the event in question?

 
Re: How do I invalidate arguments for ships that have left the mission?
The general problem is hopefully something I can communicate: when you have (when-argument (any-of <some ships...>) <condition> <body...>), each of the body nodes will be evaluated for each valid argument for which the condition is true, right? The thing is, a lot of sexps short-circuit by returning NAN_FOREVER or KNOWN_TRUE when called on destroyed or departed ships, and the short circuiting is never reset when the argument changes. It is for the condition node, which is basically how we worked around Battuta's problem, but the fact that nodes in the body can get 'stuck' like this is a massive footgun and requires FREDders to know far too much about the guts of the SEXP evaluator to understand and avoid. I think when-argument should really just flush the tree between runs, although I'm somewhat concerned that someone has somehow made missions that rely on this bizarre behaviour.
The good Christian should beware of mathematicians, and all those who make empty prophecies. The danger already exists that the mathematicians have made a covenant with the devil to darken the spirit and to confine man in the bonds of Hell.

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: How do I invalidate arguments for ships that have left the mission?
I'm more worried about the performance implications of flushing the entire tree every evaluation than I am about breaking backwards compatibility.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: How do I invalidate arguments for ships that have left the mission?
Give me a simple case where I can see this behaviour. I'm still kind of lost as to why it's an issue.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: How do I invalidate arguments for ships that have left the mission?
Event repeating once every second (via high trigger count) that accepts a list of posters and, if they are in the mission, does something.

Code: [Select]
When-argument (Battuta, Karajorma, Phantom Hoover)
—true
—when
——is-in-mission(argument) = true
——do-something(argument)

If Battuta leaves, is-in-mission returns NAN_FOREVER (since Battuta is gone) and gets stuck there: it also returns NAN_FOREVER for Karajorma and Phantom Hoover even if they are still in the mission.

However, this works:

Code: [Select]
When-argument (Battuta, Karajorma, Phantom Hoover)
—is-in-mission(argument) = true
—do-something(argument)

Because the outermost 'when' gets 'flushed' (whatever this means, coder speak) when it moves to a new argument.


« Last Edit: November 29, 2020, 10:16:22 am by General Battuta »

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: How do I invalidate arguments for ships that have left the mission?
Just out of interest, what happens if you have

Code: [Select]
When-argument (Battuta, Karajorma, Phantom Hoover)
—any-sexp-that-will-always-return-true(argument)
—when
——is-in-mission(argument) = true
——do-something(argument)

Cause I suspect this might be a consequence of using an inner conditional when the outer one is doing nothing with the argument.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: How do I invalidate arguments for ships that have left the mission?
Oh, interesting. I'll check...

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: How do I invalidate arguments for ships that have left the mission?
Changing the outermost 'true' to "has-arrived-delay <argument>" makes the entire event stop evaluating? Even though the ships are present at mission start?? I'm confused

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: How do I invalidate arguments for ships that have left the mission?
If I change the outermost "when" to "not is ship-stealthy <argument>", which should always return true:

The moment one of the ships in the argument list dies, the inner check (actually an is-ship-class, not in-mission) breaks for all ships of the same class.

So:

Code: [Select]
When-argument (Battuta, Karajorma, Phantom Hoover)
—not is-ship-stealthy(argument)
—when
——is-class(argument) = Poster
——do-something(argument)

This will break for all ships in the argument list the moment one of those ships is destroyed (which changes is-class to NAN_FOREVER).

Did I, uh, correctly execute the question?

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: How do I invalidate arguments for ships that have left the mission?
Changing the outermost 'true' to "has-arrived-delay <argument>" makes the entire event stop evaluating? Even though the ships are present at mission start?? I'm confused

I'm guessing ships present at mission start haven't actually 'arrived'?

Further test, if I do

Code: [Select]
When-argument (Battuta, Karajorma, Phantom Hoover)
—not is-disarmed-delay(argument)
—when
——is-class(argument) = Poster
——do-something(argument)

If I destroy any of the ships in the argument list, the event breaks for all ships of the class. is-class is short circuiting to NAN_FOREVER for the whole argument list, I think.

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: How do I invalidate arguments for ships that have left the mission?
Short-circuiting is the correct behavior.  The when-argument sexp is designed to complete like any normal event once it finds itself in a state where it can be short-circuited.  If short-circuiting is not desired, then every-time should be used.

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: How do I invalidate arguments for ships that have left the mission?
Short-circuiting is the correct behavior.  The when-argument sexp is designed to complete like any normal event once it finds itself in a state where it can be short-circuited.  If short-circuiting is not desired, then every-time should be used.
The when-argument isn't short-circuiting; the when inside the when-argument is short-circuiting.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: How do I invalidate arguments for ships that have left the mission?
Hmm, that would make a difference, wouldn't it.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: How do I invalidate arguments for ships that have left the mission?
But every-time should be flushing that inner when, right?
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
Re: How do I invalidate arguments for ships that have left the mission?
Pull request #2942 should fix this, although being a FREDless linux user I have not been able to directly confirm this.
The good Christian should beware of mathematicians, and all those who make empty prophecies. The danger already exists that the mathematicians have made a covenant with the devil to darken the spirit and to confine man in the bonds of Hell.

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: How do I invalidate arguments for ships that have left the mission?
But every-time should be flushing that inner when, right?

Every-time would flush it, but every-time isn't being used here.


Pull request #2942 should fix this, although being a FREDless linux user I have not been able to directly confirm this.

The problem is, we need to be certain that 1) we have identified the correct root cause, and 2) the change will not adversely affect any other missions.  This issue is confusing enough that I don't think #1 or #2 are certain.

 

Offline Colonol Dekker

  • HLP is my mistress
  • 213
  • Aken Tigh Dekker
    • My old squad sub-domain
Re: How do I invalidate arguments for ships that have left the mission?
Whatever this is for, I look forward to the final output.