How to use random action?

Level 3
Joined
Mar 30, 2023
Messages
16
I want
Hello
I want to say to Trigger:
Do one of the instructions randomly
Which action should I use in Triggers?








is this?
 

Attachments

  • Shot 0002.png
    Shot 0002.png
    10 KB · Views: 15
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,884
Actually is like this:

For 2 possibilities:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Random integer number between 1 and 2) Equal to 1
    • Then - Actions
      • -------- Actions 1 --------
    • Else - Actions
      • -------- Actions 2 --------
For more than 2 posibilities:
  • Set VariableSet RandomNumber = (Random integer number between 1 and 3)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • RandomNumber Equal to 1
    • Then - Actions
      • -------- Actions 1 --------
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RandomNumber Equal to 2
        • Then - Actions
          • -------- Actions 2 --------
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomNumber Equal to 3
            • Then - Actions
              • -------- Actions 3 --------
            • Else - Actions
What you posted is a "For loop" which is for iterate some actions while an integer is increasing its value from a minimum to maximum after each iteration.
 
Level 41
Joined
Feb 27, 2007
Messages
5,235
Just to note: Herly showed all of those if-blocks being nested inside each other (block 2 is in the “else” of block 1, 3 is in else of 2, etc.) but that’s not necessary. They can all be sequential after each other. Since your randomly chosen number is only one number it will only match with one condition block and the rest will be ignored.

Depending on how different the random things are, another viable solution is to put information about those actions into some array(s) on map init. Then pick a random number and do whatever you should do to YourDataArrays[YourRandomNumber].
 
Level 41
Joined
Feb 27, 2007
Messages
5,235
I know why you wrote it that way, it's just entirely unnecessary in the vast majority of situations and makes the trigger look annoyingly convoluted. It's a thing I see novice mapmakers do all the time and it bothers me because it removes clarity in an attempt to optimize something that doesn't need to be optimized.

Some thousands of conditions could be checked every 0.5 seconds and you'd never notice. If those conditions require other code (like creating points to check a distance, other handle operations, etc.) then it may be prudent to skip them depending on context. Trying to hyper-optimize in GUI is a fool's errand; you're fighting waaaaaay bigger fish in the form of GUI's nested condition bullshit, wrappers that literally double or triple your function-call count, etc..
 
Level 24
Joined
Jun 26, 2020
Messages
1,884
I know why you wrote it that way, it's just entirely unnecessary in the vast majority of situations and makes the trigger look annoyingly convoluted. It's a thing I see novice mapmakers do all the time and it bothers me because it removes clarity in an attempt to optimize something that doesn't need to be optimized.

Some thousands of conditions could be checked every 0.5 seconds and you'd never notice. If those conditions require other code (like creating points to check a distance, other handle operations, etc.) then it may be prudent to skip them depending on context. Trying to hyper-optimize in GUI is a fool's errand; you're fighting waaaaaay bigger fish in the form of GUI's nested condition bullshit, wrappers that literally double or triple your function-call count, etc..
Honestly I just keep doing it to don't lose the habit of not doing something like:

if value == 1 then
endif
if value == 2 then
endif
etc

even if I'm not using GUI
 
Level 3
Joined
Mar 30, 2023
Messages
16
Actually is like this:

For 2 possibilities:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Random integer number between 1 and 2) Equal to 1
    • Then - Actions
      • -------- Actions 1 --------
    • Else - Actions
      • -------- Actions 2 --------
For more than 2 posibilities:
  • Set VariableSet RandomNumber = (Random integer number between 1 and 3)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • RandomNumber Equal to 1
    • Then - Actions
      • -------- Actions 1 --------
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RandomNumber Equal to 2
        • Then - Actions
          • -------- Actions 2 --------
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomNumber Equal to 3
            • Then - Actions
              • -------- Actions 3 --------
            • Else - Actions
What you posted is a "For loop" which is for iterate some actions while an integer is increasing its value from a minimum to maximum after each iteration.

Just to note: Herly showed all of those if-blocks being nested inside each other (block 2 is in the “else” of block 1, 3 is in else of 2, etc.) but that’s not necessary. They can all be sequential after each other. Since your randomly chosen number is only one number it will only match with one condition block and the rest will be ignored.

Depending on how different the random things are, another viable solution is to put information about those actions into some array(s) on map init. Then pick a random number and do whatever you should do to YourDataArrays[YourRandomNumber].
Thank you guys:D
 
Top