Modding, Mission Design, and Coding > The FRED Workshop

when-argument, random-multiple-of - Questions

(1/2) > >>

0rph3u5:
So, I had a nice time FREDing today ... which left me with a few questions on how random-of and random-multiple-of arguments list work.

1) If argument is randomly picked from the list does it at any time check if it is valid?
(e.g. the list is 6 ships, 2 are already destroyed and 2 are still to arrive - automatically exclude the 4 or do I have to narrow that somehow)

2) When does it actually pick an argument (and if yes to 1 - when does it check it)?
(event.log doesn't help because it puts the result of random-multiple-of on top before all the checks, which are also written in reverse order)

I would be very grateful for some answers.

Reason:
I've been trying to get some of my randomisation working without proxy variables to keep the number of variables used per mission down - so I have more space for mission to mission transfers and campaign mechanics; the real wild stuff is still in the tipeline. Mostly its stuff that small and inoffensive, such as minor variations on the dialogue or randomly picking one of the redshirts to say this or that line. Some of it is a bit consequential, such as if two destroyers are in a mission, which one gets to send the supply ship - and then reseting that if one of them is destroyed.

But I am also looking to the future and how to do stuff like "envoirnmental effects" or automatically triggering abilities for named squadmates or supporting craft in the ">bomber, <cruiser"-range (I meant it when I said that I wanted those stinking capital ships out of my missions).

karajorma:

--- Quote from: 0rph3u5 on March 26, 2020, 07:31:49 pm ---So, I had a nice time FREDing today ... which left me with a few questions on how random-of and random-multiple-of arguments list work.

1) If argument is randomly picked from the list does it at any time check if it is valid?
(e.g. the list is 6 ships, 2 are already destroyed and 2 are still to arrive - automatically exclude the 4 or do I have to narrow that somehow)
--- End quote ---

Nope. The game absolutely won't check if the argument is valid in that way since it has literally no way to do so. As far as the game is concerned, an argument is a string. The later SEXPs might treat that string as a ship name or something, but there is no way for the random-of SEXP to know that. The only way to validate or invalidate those strings is by using the corresponding invalidate-argument SEXPs.


--- Quote ---2) When does it actually pick an argument (and if yes to 1 - when does it check it)?
(event.log doesn't help because it puts the result of random-multiple-of on top before all the checks, which are also written in reverse order)

--- End quote ---

Basically the first thing the when-argument SEXP does is evaluate the corresponding -of SEXP which in this case means that the random-multiple-of will be evaluated before any of the triggers. That unfortunately means you can't do any sort of trickery as a FREDder using the perform-actions SEXP to invalidate the ships that have been destroyed before it picks. What you could do though is use an if-then-else along these lines

when-argument
-random-multiple-of
-- List of ships
-true
-if-then-else
--is-destroyed-delay
---<argument>
--invalidate-argument
---<argument>
-- Whatever you wanted to do.

The drawback of this though is that you can't guarantee when it will actually work. You need to tell it to repeat and then put up with it picking a random ship each frame, testing if it is alive, and invalidating the ship and waiting for the next frame if it wasn't. This won't work if split-second timing is required and you can't wait for the SEXP to repeat.

Nightmare:

--- Quote from: 0rph3u5 on March 26, 2020, 07:31:49 pm ---So, I had a nice time FREDing today ... which left me with a few questions on how random-of and random-multiple-of arguments list work.

1) If argument is randomly picked from the list does it at any time check if it is valid?
(e.g. the list is 6 ships, 2 are already destroyed and 2 are still to arrive - automatically exclude the 4 or do I have to narrow that somehow)

--- End quote ---

If in doubt, always expect the worst.

0rph3u5:

--- Quote from: karajorma on March 26, 2020, 08:35:44 pm ---*snip*

--- End quote ---

Knowing that helps ...

So I've been trying what's below (hidden because deffective) - and it didn't work

Hidden Text: defective thing • ShowNote: The original had a repeat count "9999999" and intervall time 0

--- Code: ---$Formula: ( when-argument
   ( any-of
      "Aquarius 1"
      "Aquarius 2"
      "Aries 1"
      "Aries 2"
      "Cancer 1"
      "Cancer 2"
      "Capricorn 1"
      "Capricorn 2"
      "Gemini 1"
      "Gemini 2"
      "Leo 1"
      "Leo 2"
      "Libra 1"
      "Libra 2"
      "Pisces 1"
      "Pisces 2"
      "Sagittarius 1"
      "Sagittarius 2"
   )
   ( and
      ( string-equals
         "@ECM_Switch[AUS]"
         "AN"
      )
      ( = @ECM-cooldown[0] 0 )
      ( string-equals
         "@ECM-target[empty]"
         "empty"
      )
      ( is-in-mission "<argument>" )
      ( false )
   )
   ( invalidate-all-arguments )
   ( when
      ( has-arrived-delay 0 "Aquarius" )
      ( validate-argument
         "Aquarius 1"
         "Aquarius 2"
      )
   )
   ( when
      ( has-arrived-delay 0 "Aries" )
      ( validate-argument
         "Aries 1"
         "Aries 2"
      )
   )
   ( when
      ( has-arrived-delay 0 "Cancer" )
      ( validate-argument
         "Cancer 1"
         "Cancer 2"
      )
   )
   ( when
      ( has-arrived-delay 0 "Capricorn" )
      ( validate-argument
         "Capricorn 1"
         "Capricorn 2"
      )
   )
   ( when
      ( has-arrived-delay 0 "Gemini" )
      ( validate-argument
         "Gemini 1"
         "Gemini 2"
      )
   )
   ( when
      ( has-arrived-delay 0 "Leo" )
      ( validate-argument "Leo 1" "Leo 2" )
   )
   ( when
      ( has-arrived-delay 0 "Libra" )
      ( validate-argument
         "Libra 1"
         "Libra 2"
      )
   )
   ( when
      ( has-arrived-delay 0 "Pisces" )
      ( validate-argument
         "Pisces 1"
         "Pisces 2"
      )
   )
   ( when
      ( has-arrived-delay 0 "Sagittarius" )
      ( validate-argument
         "Sagittarius 1"
         "Sagittarius 2"
      )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Aquarius 1"
      )
      ( invalidate-argument "Aquarius 1" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Aquarius 2"
      )
      ( invalidate-argument "Aquarius 2" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Aries 1"
      )
      ( invalidate-argument "Aries 1" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Aries 2"
      )
      ( invalidate-argument "Aries 2" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Cancer 1"
      )
      ( invalidate-argument "Cancer 1" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Cancer 2"
      )
      ( invalidate-argument "Cancer 2" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Capricorn 1"
      )
      ( invalidate-argument "Capricorn 1" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Capricorn 2"
      )
      ( invalidate-argument "Capricorn 2" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Gemini 1"
      )
      ( invalidate-argument "Gemini 1" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Gemini 2"
      )
      ( invalidate-argument "Gemini 2" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Libra 1"
      )
      ( invalidate-argument "Libra 1" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Libra 2"
      )
      ( invalidate-argument "Libra 2" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Leo 1"
      )
      ( invalidate-argument "Leo 1" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Leo 2"
      )
      ( invalidate-argument "Leo 2" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Pisces 1"
      )
      ( invalidate-argument "Pisces 1" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Pisces 2"
      )
      ( invalidate-argument "Pisces 2" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Sagittarius 1"
      )
      ( invalidate-argument "Sagittarius 1" )
   )
   ( when
      ( destroyed-or-departed-delay
         0
         "Sagittarius 2"
      )
      ( invalidate-argument "Sagittarius 2" )
   )
   ( modify-variable
      @ECM-effect[0]
      ( rand-multiple 1 3 )
   )
   ( modify-variable
      "@ECM-target[empty]"
      "<argument>"
   )
   ( modify-variable
      @ECM-ctrl-number[0]
      ( + @ECM-ctrl-number[0] 1 )
   )
)
+Name: faulty herc aura
+Repeat Count: 1
+Interval: 1

--- End code ---

However these guys work, for some reason:

Hidden Text: working things • Show.

--- Code: ---$Formula: ( when-argument
   ( random-multiple-of
      "Aquarius 1"
      "Aquarius 2"
      "Aries 1"
      "Aries 2"
      "Cancer 1"
      "Cancer 2"
      "Capricorn 1"
      "Capricorn 2"
      "Gemini 1"
      "Gemini 2"
      "Leo 1"
      "Leo 2"
      "Libra 1"
      "Libra 2"
      "Pisces 1"
      "Pisces 2"
      "Sagittarius 1"
      "Sagittarius 2"
   )
   ( and
      ( string-equals
         "@ECM_Switch[AUS]"
         "AN"
      )
      ( = @ECM-cooldown[0] 0 )
      ( string-equals
         "@ECM-target[empty]"
         "empty"
      )
      ( has-arrived-delay 0 "<argument>" )
      ( not
         ( destroyed-or-departed-delay
            0
            "<argument>"
         )
      )
   )
   ( modify-variable
      @ECM-effect[0]
      ( rand-multiple 1 3 )
   )
   ( modify-variable
      "@ECM-target[empty]"
      "<argument>"
   )
   ( modify-variable
      @ECM-ctrl-number[0]
      ( + @ECM-ctrl-number[0] 1 )
   )
)
+Name: ECM Herc Aura
+Repeat Count: -1
+Trigger Count: 999999999
+Interval: 0
+Event Log Flags: ( "true" "false" "first repeat" "first trigger" )

--- End code ---


--- Code: ---$Formula: ( when-argument
   ( random-of "Hope" "Sovereign" )
   ( and
      ( has-arrived-delay 210 "Prophecy" )
      ( not
         ( destroyed-or-departed-delay
            0
            "Prophecy"
         )
      )
      ( not
         ( destroyed-or-departed-delay
            0
            "Hope"
            "Sovereign"
         )
      )
   )
   ( when
      ( is-destroyed-delay 0 "Hope" )
      ( invalidate-argument "Hope" )
   )
   ( when
      ( is-destroyed-delay 0 "Sovereign" )
      ( invalidate-argument "Sovereign" )
   )
   ( when
      ( string-equals
         "<argument>"
         "Sovereign"
      )
      ( send-message
         "Sovereign"
         "High"
         "destroyer duel 1a - sov"
      )
   )
   ( when
      ( string-equals "<argument>" "Hope" )
      ( send-message
         "Hope"
         "High"
         "destroyer duel 1b - hope"
      )
   )
)
+Name: msg destroyer duel 1
+Repeat Count: 1
+Interval: 1

--- End code ---
.

*shurgs*

karajorma:
That doesn't surprise me at all. In the first event you are invalidating all the arguments after the game has already picked one that frame. So it's going to pick one that is invalid pretty often. I can't even remember what happens if you try to stick an invalid argument into a variable but it's definitely not advised.

Navigation

[0] Message Index

[#] Next page

Go to full version