Half-working random number effect

Level 12
Joined
Jul 5, 2014
Messages
551
I'm setting up a test trigger which basically serves as random effect while a hero has a particular item. It seems to work to a degree but sometimes it takes more than the periodic event to roll a number. If I'm doing it wrong, why it works occasionally?

  • chaos
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 3) Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: 1
          • Unit - Set life of ChaosInflicted to ((Life of ChaosInflicted) - 200.00)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 3) Equal to 2
            • Then - Actions
              • Game - Display to (All players) the text: 2
              • Unit - Set mana of ChaosInflicted to ((Mana of ChaosInflicted) - 100.00)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Random integer number between 1 and 3) Equal to 3
                • Then - Actions
                  • Game - Display to (All players) the text: 3
                  • Unit - Set life of ChaosInflicted to ((Life of ChaosInflicted) + 200.00)
                • Else - Actions
 
Level 29
Joined
Sep 26, 2009
Messages
2,594
Each condition runs its own random number check, so each condition has 33% chance to hit its respective "Then actions" block.
To fix this, use integer variable. Assign random number between 1 and 3 into that variable. Then update your conditions so that they check if value of that integer variable is 1 or 2 or 3

Edit: pseudo code of what I mean
Code:
set randomNum = random number between 1 and 3
if randomNum == 1 then
    Decrease life of ChaosInflicted by 200
else if randomNum == 2 then
   Decrease mana of ChaosInflicted by 100
else if randomNum == 3 then
   Increase life of ChaosInflicted by 200 
end
 
Level 12
Joined
Jul 5, 2014
Messages
551
Each condition runs its own random number check, so each condition has 33% chance to hit its respective "Then actions" block.
To fix this, use integer variable. Assign random number between 1 and 3 into that variable. Then update your conditions so that they check if value of that integer variable is 1 or 2 or 3

Edit: pseudo code of what I mean
Code:
set randomNum = random number between 1 and 3
if randomNum == 1 then
    Decrease life of ChaosInflicted by 200
else if randomNum == 2 then
   Decrease mana of ChaosInflicted by 100
else if randomNum == 3 then
   Increase life of ChaosInflicted by 200
end
Something like this?

  • chaos damage
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Set ChaosDice = (Random integer number between 1 and 3)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ChaosDice Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: 1
          • Unit - Set life of ChaosInflicted to ((Life of ChaosInflicted) - 200.00)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ChaosDice Equal to 2
            • Then - Actions
              • Game - Display to (All players) the text: 2
              • Unit - Set mana of ChaosInflicted to ((Mana of ChaosInflicted) - 100.00)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ChaosDice Equal to 3
                • Then - Actions
                  • Game - Display to (All players) the text: 3
                  • Unit - Set life of ChaosInflicted to ((Life of ChaosInflicted) + 200.00)
                • Else - Actions
 
Level 29
Joined
Sep 26, 2009
Messages
2,594
yes :thumbs_up:
You can actually put the actions for ChaosDice == 3 into the second If/Then/Else's "Else actions" block. Because if you only have 3 options: 1, 2 and 3 and ChaosDice is neither 1 nor 2, then it must be 3, no need to check it then :)

Edit: I mean like so:
  • chaos damage
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Set ChaosDice = (Random integer number between 1 and 3)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ChaosDice Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: 1
          • Unit - Set life of ChaosInflicted to ((Life of ChaosInflicted) - 200.00)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ChaosDice Equal to 2
            • Then - Actions
              • Game - Display to (All players) the text: 2
              • Unit - Set mana of ChaosInflicted to ((Mana of ChaosInflicted) - 100.00)
            • Else - Actions
              • Game - Display to (All players) the text: 3
              • Unit - Set life of ChaosInflicted to ((Life of ChaosInflicted) + 200.00)
 
Top