Author Topic: when-argument, random-multiple-of - Questions  (Read 1437 times)

0 Members and 1 Guest are viewing this topic.

Offline 0rph3u5

  • 211
  • Oceans rise. Empires fall.
when-argument, random-multiple-of - Questions
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).
"As you sought to steal a kingdom for yourself, so must you do again, a thousand times over. For a theft, a true theft, must be practiced to be earned." - The terms of Nyrissa's curse, Pathfinder: Kingmaker

==================

"I am Curiosity, and I've always wondered what would become of you, here at the end of the world." - The Guide/The Curious Other, Othercide

"When you work with water, you have to know and respect it. When you labour to subdue it, you have to understand that one day it may rise up and turn all your labours into nothing. For what is water, which seeks to make all things level, which has no taste or colour of its own, but a liquid form of Nothing?" - Graham Swift, Waterland

"...because they are not Dragons."

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: when-argument, random-multiple-of - Questions
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)

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)

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.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 
Re: when-argument, random-multiple-of - Questions
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)

If in doubt, always expect the worst.

 

Offline 0rph3u5

  • 211
  • Oceans rise. Empires fall.
Re: when-argument, random-multiple-of - Questions
*snip*

Knowing that helps ...

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

Hidden Text: defective thing • Show
Note: The original had a repeat count "9999999" and intervall time 0
Code: [Select]
$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

However these guys work, for some reason:

Hidden Text: working things • Show
.
Code: [Select]
$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" )

Code: [Select]
$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
.

*shurgs*
« Last Edit: March 26, 2020, 10:07:26 pm by 0rph3u5 »
"As you sought to steal a kingdom for yourself, so must you do again, a thousand times over. For a theft, a true theft, must be practiced to be earned." - The terms of Nyrissa's curse, Pathfinder: Kingmaker

==================

"I am Curiosity, and I've always wondered what would become of you, here at the end of the world." - The Guide/The Curious Other, Othercide

"When you work with water, you have to know and respect it. When you labour to subdue it, you have to understand that one day it may rise up and turn all your labours into nothing. For what is water, which seeks to make all things level, which has no taste or colour of its own, but a liquid form of Nothing?" - Graham Swift, Waterland

"...because they are not Dragons."

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: when-argument, random-multiple-of - Questions
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.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline 0rph3u5

  • 211
  • Oceans rise. Empires fall.
Re: when-argument, random-multiple-of - Questions
I can't even remember what happens if you try to stick an invalid argument into a variable but it's definitely not advised.

Nothing happens - Event.log reports that SEXP as FALSE and no change in the variable
"As you sought to steal a kingdom for yourself, so must you do again, a thousand times over. For a theft, a true theft, must be practiced to be earned." - The terms of Nyrissa's curse, Pathfinder: Kingmaker

==================

"I am Curiosity, and I've always wondered what would become of you, here at the end of the world." - The Guide/The Curious Other, Othercide

"When you work with water, you have to know and respect it. When you labour to subdue it, you have to understand that one day it may rise up and turn all your labours into nothing. For what is water, which seeks to make all things level, which has no taste or colour of its own, but a liquid form of Nothing?" - Graham Swift, Waterland

"...because they are not Dragons."

 

Online Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: when-argument, random-multiple-of - Questions
"Invalid" simply means the argument won't be selected.  It has nothing to do with whether it's a plausible argument, e.g. if it's a ship that's present or not.