Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: Rodo on March 12, 2014, 09:51:13 pm

Title: Endless docking loop of doom!
Post by: Rodo on March 12, 2014, 09:51:13 pm
Obviously my mind has reached it's limits, and thus I turn to ask for help from the greater wizards.
So... any of you guys knows how to make this work?.

It's supposed to be an endless docking loop between 3 ships, check attached mission for details.

[attachment deleted by an evil time traveler]
Title: Re: Endless docking loop of doom!
Post by: Goober5000 on March 12, 2014, 11:23:05 pm
This is tricky.  I'm fairly sure I know what's going on, but fixing it will involve deeper thinking.

Take a look at this sexp...
Code: [Select]
   ( and
      ( has-docked-delay
         "A"
         "B"
         @dockCount[1]
         5
      )
      ( = @r1True[1] 1 )
   )

Do not assume that and requires its conditions to be true simultaneously.  I suspect what happens is that the has-docked-delay portion becomes true all over again after the trigger delay elapses.  Thereafter, it only waits on the r1True portion, which itself becomes true as soon as the transport docks with the second ship.

I think you're going to have to come up with some kind of state machine.  Make a series of sexps, each testing only one condition on a trigger loop and storing the result in a variable: docked with A, undocked with A, docked with C, undocked with C.  Then make another series of sexps that issue orders to ship A depending on what the variable values are.
Title: Re: Endless docking loop of doom!
Post by: karajorma on March 13, 2014, 12:40:33 am
It is indeed that. Has-docked-delay returns SEXP_KNOWN_TRUE. This is actually one of the few cases when you should be using every-time rather than when.

Obviously my mind has reached it's limits, and thus I turn to ask for help from the greater wizards.

I notice you don't have any event.log flags set. If you'd used those, it would have shown you the issue immediately (Whether you actually had the FRED knowledge required to interpret it, is another issue though).
Title: Re: Endless docking loop of doom!
Post by: Rodo on March 13, 2014, 06:52:20 am
Yeah I suspected about the docked-delay being the culprit.
Ok, I'll have a go at your suggestions. Thanks!
Title: Re: Endless docking loop of doom!
Post by: Goober5000 on March 13, 2014, 09:58:38 am
It is indeed that. Has-docked-delay returns SEXP_KNOWN_TRUE.

It's not only that, it's the fact that has-docked-delay checks the mission log.  So it's possible for it to become true even if the ship isn't actually docked at the time the sexp fires.

I suppose it wouldn't be a bad idea to add is-docked, in the same way that we have is-tagged.
Title: Re: Endless docking loop of doom!
Post by: karajorma on March 13, 2014, 10:22:21 am
It's not only that, it's the fact that has-docked-delay checks the mission log.  So it's possible for it to become true even if the ship isn't actually docked at the time the sexp fires.


Well you can get around that one with a use of has-undocked-delay. I'll agree that it's much more cumbersome than an is-docked SEXP would be but it should work.
Title: Re: Endless docking loop of doom!
Post by: 666maslo666 on March 14, 2014, 02:15:39 pm
I suppose it wouldn't be a bad idea to add is-docked, in the same way that we have is-tagged.

Please do, I made such feature request a year ago:

http://www.hard-light.net/forums/index.php?topic=84072.msg1679278
Title: Re: Endless docking loop of doom!
Post by: Rodo on March 16, 2014, 12:42:02 pm
Well after a few tries, I'm inclined to believe this is impossible to achieve right now.

Bottom line seems to be that if I cannot check exactly the moment when given ship is docked with another one (to control when to issue orders) this cannot be achieved.

State machine works, but only for the first iteration. On the second run it will not perform due to all steps being already true, thus making impossible to issue orders with appropriate timing.

I tried a lot of different approaches, and I'm fairly sure some will perform better than others but if someone wants to use my tries here I attach the mission for you guys to play with it.

[attachment deleted by an evil time traveler]
Title: Re: Endless docking loop of doom!
Post by: karajorma on March 17, 2014, 12:09:10 am
To be honest, I can't make head nor tails of what you're trying to do in your test mission. Having poorly labelled variables and events just makes things very confusing for someone else.

But you still seem to be using when in the first 4 events and that definitely won't work for the reasons above.
Title: Re: Endless docking loop of doom!
Post by: 666maslo666 on March 17, 2014, 07:15:38 am
Well after a few tries, I'm inclined to believe this is impossible to achieve right now.

Bottom line seems to be that if I cannot check exactly the moment when given ship is docked with another one (to control when to issue orders) this cannot be achieved.

State machine works, but only for the first iteration. On the second run it will not perform due to all steps being already true, thus making impossible to issue orders with appropriate timing.

I tried a lot of different approaches, and I'm fairly sure some will perform better than others but if someone wants to use my tries here I attach the mission for you guys to play with it.

I too am not sure what exactly you want to do. But maybe you can use separate has-docked-delay events for more iterations. For second iteration, set "The number of times they have to have docked" to 2 etc. Thats what I do in my mod and it works essentialy as is-docked would, and works for repeated and daisy chained dockings, too. It wont be an endless loop, tough.
Title: Re: Endless docking loop of doom!
Post by: 666maslo666 on March 17, 2014, 07:49:44 am
Here is simple mission with endless loop of docking and undocking, maybe it will help you.

[attachment deleted by an evil time traveler]
Title: Re: Endless docking loop of doom!
Post by: Rodo on March 17, 2014, 09:05:21 am
Mmm, yeah I get what you say. That mission is the result of multiple test iterations, so it's bound to be somewhat confusing.
After a few attempts I just lost the will to keep the code neat.

I'm missing your point on the use of when on the first 4 sexps, IIRC those where the sexps that issue the orders to the transport. I cannot use an every-time there, the transport will just stop responding if I spam it with orders endlessly.


About the concept of the mission itself:

3 ships.
2 of them staying still.
1 of them switching to dock on the first on one, then undocking and moving to dock on the second one. Repeat last step in an endless loop.

Thanks maslo, I don't have fred right here, but from what I could understand checking the mission on notepad your example will not work for what I want to achieve. It's just docking endlessly with a single ship, I want to use both.
Title: Re: Endless docking loop of doom!
Post by: 666maslo666 on March 17, 2014, 12:54:46 pm
About the concept of the mission itself:

3 ships.
2 of them staying still.
1 of them switching to dock on the first on one, then undocking and moving to dock on the second one. Repeat last step in an endless loop.

Thanks maslo, I don't have fred right here, but from what I could understand checking the mission on notepad your example will not work for what I want to achieve. It's just docking endlessly with a single ship, I want to use both.

OK, try this, two stationary ships and one Elysium going endlesly between them.

[attachment deleted by an evil time traveler]
Title: Re: Endless docking loop of doom!
Post by: Rodo on March 17, 2014, 07:35:06 pm
Ohhh it works like charm, and it bugs me because I've already tried that and things didn't work out!
But never fear, I see where I ****ed it.

Thanks for the help guys, and sorry you had to put up with my dumbness  ;)
Title: Re: Endless docking loop of doom!
Post by: karajorma on March 18, 2014, 05:42:37 am
OK, try this, two stationary ships and one Elysium going endlesly between them.

Yep, that's pretty much what I was trying to point out.

This sort of issue is the real reason for the existence of the every-time operators. Otherwise you might as well just use repeated when with a delay of 0. It is actually less CPU intensive to do so.