• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

can trigger lines be skipped?

Status
Not open for further replies.
Level 4
Joined
Jan 5, 2014
Messages
79
Hello, I have made a rather complicated trigger with 0.02 periodic event. Is is possible, that thanks to being so complicated and so often used, it sometimes ignores some lines? Coz it seems so in my game.
 
If you have too many actions in a row or an infinite loop, then the trigger may hit the op limit (in which case, it will halt where it is, ignoring the rest of the actions).

That might be the case for you. To check, add a message at the end of the trigger (outside all the if/then/else and loop statements). If it shows up, then that means all the code was successfully evaluated. If it doesn't show up, then you probably hit the op limit (if so, post the trigger here and we can help).
 
Level 4
Joined
Jan 5, 2014
Messages
79
As the trigger has the 0.02 periodic event, I tried this

  • Knockback Engine for Pool
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
    • Actions
      • Set TempInteger1 = (TempInteger1 + 1)
      • Blah blah blah, my trigger
      • Set TempPoint1 = (Position of Cue)
      • Set TempInteger2 = (TempInteger2 + 1)
      • Floating Text - Create floating text that reads (String((TempInteger1 - TempInteger2))) at TempPoint1 with Z offset 120.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Change the lifespan of (Last created floating text) to 0.10 seconds
      • Custom script: call RemoveLocation(udg_TempPoint1)
It shows always zero, so this shouldnt be the case. (the first TempInteger increase whenever the trigger starts and the second one whenever it ends)
 
Level 4
Joined
Jan 5, 2014
Messages
79
Show the full triggers please.

OK, but it is complicated as I have said, so be patient pls.

The game I am working on is a Pool. The following trigger is the engine for ball moving. One of the features is also init collision and bouncing. And here lies the problem. When one exact unit (White ball) collides, boolean AlreadyHitAUnit should become true. But sometimes it simply odesnt.

  • Knockback Engine for Pool Copy
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
    • Actions
      • -------- At first every unit being knockbacked is picked --------
      • Unit Group - Pick every unit in UnitsBeingKnockbacked and do (Actions)
        • Loop - Actions
          • -------- This is used to lower the bounce delay (the time until the unit can be bounced by another unit) --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load BounceDelay_Hashtable of (Key (Picked unit)) from Properties) Greater than 0
            • Then - Actions
              • Hashtable - Save ((Load BounceDelay_Hashtable of (Key (Picked unit)) from Properties) - 1) as BounceDelay_Hashtable of (Key (Picked unit)) in Properties
            • Else - Actions
          • -------- End of bounc deley decraesement --------
          • -------- --------
          • -------- Now the length of the next move is loaded and the point to which the unit should move is determinated --------
          • Set NewCurrentLenghtOfJump = (2.00 x (Square root(((2.00 x (Load CurrentEnergy_Hashtable of (Key (Picked unit)) from Properties)) / (Load Mass_Hashtable of (Key (Picked unit)) from Properties)))))
          • Set NextPosition = ((Position of (Picked unit)) offset by NewCurrentLenghtOfJump towards (Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) degrees)
          • -------- If the move should be less than 0.1 long, the knockback of the unit is terminated --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • NewCurrentLenghtOfJump Greater than 0.05
            • Then - Actions
              • -------- If the jump is longer than 0.05, now it is the time to check for collisions --------
              • -------- The first unit is saved, as a new unit is about to be picked --------
              • Set FirstUnit = (Picked unit)
              • Set FirstUnitHandle = (Picked unit)
              • -------- I had to determine somehow which units should be taken into consideration, so these are all units in 400 distance from the point of the unit, whose knockback is being calculated --------
              • Set TempGroup2 = (Units within 400.00 of NextPosition)
              • -------- The range should egual to at least two times the largest unit collision size --------
              • Unit Group - Pick every unit in TempGroup2 and do (Actions)
                • Loop - Actions
                  • -------- IMPORTANT!!! Now a new unit is picked. So lets call the firstly pickedunit the first unit and the newly picked unit the second unit --------
                  • Set TempPoint1 = (Position of (Picked unit))
                  • -------- Now it is checked, whether the unit fulfils some conditions. The long one isto compare the unit custom collision size, otherwise the conditions are selfexplenatory --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Distance between TempPoint1 and NextPosition) Less than or equal to ((Load CollisionSize_Hashtable of (Key (Picked unit)) from Properties) + ((Load CollisionSize_Hashtable of (Key FirstUnitHandle) from Properties) + 0.00))
                      • (Picked unit) Not equal to FirstUnit
                      • (Unit-type of (Picked unit)) Equal to Ball
                    • Then - Actions
                      • -------- Something for Pool (THE PART NOT WORKING) --------
                      • -------- This should set the boolean AlreadyHitAUnit to true always when the White Ball collides with another ball --------
                      • -------- The problem is that sometimes it simply doesnt work, although the White ball has surly bounced --------
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • AlreadyHitAUnit Equal to False
                          • Or - Any (Conditions) are true
                            • Conditions
                              • FirstUnit Equal to WhiteBall
                              • (Picked unit) Equal to WhiteBall
                        • Then - Actions
                          • Set AlreadyHitAUnit = True
                        • Else - Actions
                      • For each (Integer A) from 1 to 7, do (Actions)
                        • Loop - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • AlreadyHitAUnit Equal to False
                              • FirstUnit Equal to WhiteBall
                              • (Owner of Cue) Not equal to (Owner of (Picked unit))
                              • Or - Any (Conditions) are true
                                • Conditions
                                  • (Picked unit) Equal to BlueBall[(Integer A)]
                                  • (Picked unit) Equal to RedBall[(Integer A)]
                            • Then - Actions
                              • Set NumberOfRemainigStrikes = 2
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (Owner of Cue) Equal to Player 1 (Red)
                                • Then - Actions
                                  • Set NextPlayer = Player 2 (Blue)
                                • Else - Actions
                                  • Set NextPlayer = Player 1 (Red)
                              • Floating Text - Create floating text that reads (Foul!!! Opponents ball was hit first. + ((Name of (Owner of Cue)) + plays two times)) at TempPoint1 with Z offset 120.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency
                              • Floating Text - Change (Last created floating text): Disable permanence
                              • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
                              • Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
                            • Else - Actions
                      • -------- The end of the Pool part --------
                      • -------- Now, if the second unit cannot be knockbacked, the first unit will simply bounce off and no energy will be exchanged --------
                      • -------- IMPORTANT!!! Imagine that the energy is a vector with lenght of current energy, direction of the angle of knockback and position of the position of the unit --------
                      • -------- But if both first unit and second unit can be knockbacked, there will surely be some energy exchange --------
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • ((Picked unit) is in UnitsBeingKnockbacked) Equal to True
                        • Then - Actions
                          • -------- If the second unit is also being knockbacked, it is checked whether the second unit hasn't bounced recently --------
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Load BounceDelay_Hashtable of (Key (Picked unit)) from Properties) Less than or equal to 0
                            • Then - Actions
                              • -------- If the second unit hasn't bounced recently, the angle of the collision (from first to second unit) is compared with the angle of knockback of the first unit --------
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (Abs(((Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) - (Angle from (Position of FirstUnit) to (Position of (Picked unit)))))) Greater than or equal to 90.00
                                • Then - Actions
                                  • -------- If the absolute value of the of angles diffrence is lower than 90, both units will exchange part of their knockback --------
                                  • -------- Now lets divide knockback of both units into two parts, One paralell to the direction from the first to the second unit, one tangent to this direction. --------
                                  • -------- Both units will now exchange their part of the knockback paralell to the direction from the first one to the second one. --------
                                  • Set KnockbackBeingAdded = ((Load CurrentEnergy_Hashtable of (Key FirstUnitHandle) from Properties) x (Sin((Abs(((Load AngelOfKnockback_Hashtable of (Key FirstUnitHandle) from Properties) - (Angle from (Position of FirstUnit) to (Position of (Picked unit)))))))))
                                  • Set AngleOfKnockbackBeingAdded = (Angle from (Position of FirstUnit) to (Position of (Picked unit)))
                                  • Set KnockbackTarget = (Picked unit)
                                  • Trigger - Run Adding New Knockback <gen> (checking conditions)
                                  • Set AngleOfKnockbackBeingAdded = (AngleOfKnockbackBeingAdded + 180.00)
                                  • Set KnockbackTarget = FirstUnit
                                  • Trigger - Run Adding New Knockback <gen> (checking conditions)
                                  • Set KnockbackBeingAdded = ((Load CurrentEnergy_Hashtable of (Key (Picked unit)) from Properties) x (Sin((Abs(((Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) - (Angle from (Position of (Picked unit)) to (Position of FirstUnit))))))))
                                  • Set AngleOfKnockbackBeingAdded = (Angle from (Position of (Picked unit)) to (Position of FirstUnit))
                                  • Set KnockbackTarget = FirstUnit
                                  • Trigger - Run Adding New Knockback <gen> (checking conditions)
                                  • Set AngleOfKnockbackBeingAdded = (AngleOfKnockbackBeingAdded + 180.00)
                                  • Set KnockbackTarget = (Picked unit)
                                  • Trigger - Run Adding New Knockback <gen> (checking conditions)
                                  • -------- And to protect the system from one bug, some bouncing delay is saved to both of the units --------
                                  • Hashtable - Save BasicBounceDelay as BounceDelay_Hashtable of (Key FirstUnitHandle) in Properties
                                  • Hashtable - Save BasicBounceDelay as BounceDelay_Hashtable of (Key (Picked unit)) in Properties
                                  • Custom script: call RemoveLocation(udg_TempPoint1)
                                  • Custom script: call RemoveLocation(udg_TempPoint2)
                                • Else - Actions
                                  • -------- If the angle diffrence is bigger, it means the second unit was hit "from behind" (compared to the angle of knockback of the second unit) --------
                                  • -------- And so the first unit will give the second unit part of its knockback, but the scond unit won't give anything to the first one --------
                                  • Set KnockbackBeingAdded = ((Load CurrentEnergy_Hashtable of (Key FirstUnitHandle) from Properties) x (Sin((Abs(((Load AngelOfKnockback_Hashtable of (Key FirstUnitHandle) from Properties) - (Angle from (Position of FirstUnit) to (Position of (Picked unit)))))))))
                                  • Set AngleOfKnockbackBeingAdded = (Angle from (Position of FirstUnit) to (Position of (Picked unit)))
                                  • Set KnockbackTarget = (Picked unit)
                                  • Trigger - Run Adding New Knockback <gen> (checking conditions)
                                  • Set AngleOfKnockbackBeingAdded = (AngleOfKnockbackBeingAdded + 180.00)
                                  • Set KnockbackTarget = FirstUnit
                                  • Trigger - Run Adding New Knockback <gen> (checking conditions)
                            • Else - Actions
                              • -------- If the second unit has bounced recently, it will behave as if it was unable to bounce. --------
                              • Set AngleOfKnockbackBeingAdded = (180.00 + ((Load AngelOfKnockback_Hashtable of (Key FirstUnitHandle) from Properties) - (2.00 x (Angle from (Position of FirstUnit) to (Position of (Picked unit))))))
                              • Hashtable - Save AngleOfKnockbackBeingAdded as AngelOfKnockback_Hashtable of (Key FirstUnitHandle) in Properties
                        • Else - Actions
                          • -------- If the second unit wasn't knockbacked, it will get the paralell (paralell to the direction from the first to the second unit) part of the first units knockback --------
                          • Set AngleOfKnockbackBeingAdded = (Angle from (Position of FirstUnit) to (Position of (Picked unit)))
                          • Set KnockbackBeingAdded = (Abs(((Load CurrentEnergy_Hashtable of (Key FirstUnitHandle) from Properties) x (Sin(((Load AngelOfKnockback_Hashtable of (Key FirstUnitHandle) from Properties) + (90.00 - AngleOfKnockbackBeingAdded)))))))
                          • Set KnockbackSource = (Position of FirstUnit)
                          • Set KnockbackTarget = (Picked unit)
                          • Trigger - Run Adding New Knockback <gen> (checking conditions)
                          • Set AngleOfKnockbackBeingAdded = (AngleOfKnockbackBeingAdded + 180.00)
                          • Set KnockbackTarget = FirstUnit
                          • Trigger - Run Adding New Knockback <gen> (checking conditions)
                    • Else - Actions
              • -------- Now, after the bouncing calculations, the new position is counted once more, coz it might have changed --------
              • Set NewCurrentLenghtOfJump = (2.00 x (Square root(((2.00 x (Load CurrentEnergy_Hashtable of (Key (Picked unit)) from Properties)) / (Load Mass_Hashtable of (Key (Picked unit)) from Properties)))))
              • Set NextPosition = ((Position of (Picked unit)) offset by NewCurrentLenghtOfJump towards (Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) degrees)
              • -------- Now the hindering trees are destroyed --------
              • Destructible - Pick every destructible within TreeDestroyingRange of NextPosition and do (Actions)
                • Loop - Actions
                  • Destructible - Kill (Picked destructible)
              • -------- And the unit is finally moved to the new position. Hurray!!! --------
              • Set NextPositionX = (X of NextPosition)
              • Set NextPositionY = (Y of NextPosition)
              • Custom script: call SetUnitX(GetEnumUnit() , udg_NextPositionX)
              • Custom script: call SetUnitY(GetEnumUnit() , udg_NextPositionY)
              • -------- And the last step, some value is subtracted from the units knockback, the value depend on many factors, such as the units mass, friction and so on --------
              • Hashtable - Save ((Load CurrentEnergy_Hashtable of (Key (Picked unit)) from Properties) - ((Load Mass_Hashtable of (Key (Picked unit)) from Properties) x ((Load Friction_Hashtable of (Key (Picked unit)) from Properties) x NewCurrentLenghtOfJump))) as CurrentEnergy_Hashtable of (Key (Picked unit)) in Properties
            • Else - Actions
              • -------- If the jump lenght should be less than 0.05, via theese lines the kockback is terminated --------
              • Unit Group - Remove (Picked unit) from UnitsBeingKnockbacked
              • Unit - Turn collision for (Picked unit) On
There is another triggers which usees the boolean:

  • Cue Changing
    • Events
      • Time - NextStrikeTimer expires
    • Conditions
    • Actions
      • Set TempGroup1 = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Ball))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in TempGroup1) Less than 16
          • AlreadyHitAUnit Equal to False
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of Cue) Equal to Player 1 (Red)
            • Then - Actions
              • Set NextPlayer = Player 2 (Blue)
            • Else - Actions
              • Set NextPlayer = Player 1 (Red)
          • Set TempPoint1 = (Position of WhiteBall)
          • Floating Text - Create floating text that reads (Foul!!! No ball was hit. + ((Name of NextPlayer) + plays two times)) at TempPoint1 with Z offset 120.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
          • Custom script: call RemoveLocation(udg_TempPoint1)
          • Set NumberOfRemainigStrikes = 2
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • NumberOfRemainigStrikes Equal to 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of Cue) Equal to Player 1 (Red)
                • Then - Actions
                  • Set NextPlayer = Player 2 (Blue)
                • Else - Actions
                  • Set NextPlayer = Player 1 (Red)
              • Set NumberOfRemainigStrikes = 1
            • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup1)
      • Unit - Change ownership of Cue to NextPlayer and Change color
      • Set AlreadyHitAUnit = False
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CanPlaceWhiteBall Equal to True
        • Then - Actions
          • Unit - Add White Ball Placing to Cue
        • Else - Actions
 
I would use KB3D or KB2D by Jad and Bribe respectively.
It's much simpler and should cease the issue quickly.

  • FirstUnit Equal to WhiteBall
  • (Picked unit) Equal to WhiteBall
Is it necessary?

Integer A/B can collide in some occasion (if it's used in multiple thread
  • , especially). It's also slower in term of operation.
 
Level 4
Joined
Jan 5, 2014
Messages
79
I would use KB3D or KB2D by Jad and Bribe respectively.
It's much simpler and should cease the issue quickly.

Not going to do that, as this system is spell focused and I havent found a way to make once knockbacked unit bounce with others (there is no unit collides event or anythinglike that)

  • FirstUnit Equal to WhiteBall
  • (Picked unit) Equal to WhiteBall
Is it necessary?

I like you studied it closely, this is really useless and I just forgot to remove it =) (EDIT: this applies for the second line)

Integer A/B can collide in some occasion (if it's used in multiple thread
  • , especially). It's also slower in term of operation.[/QUOTE]
  • Should I use "for each my variable" instaed of the "for each integer A"?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Should I use "for each my variable" instaed of the "for each integer A"?

Yes you should use a custom variable to do looping. Do not use Integer A / B. Take a look at my tutorial Things You Should Know When Using Triggers / GUI. Link is in my sig below.


You also have a ton of leaks.
This leaks a location
  • Set NextPosition = ((Position of (Picked unit)) offset by NewCurrentLenghtOfJump towards (Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) degrees)
This leaks two locations.
  • Set AngleOfKnockbackBeingAdded = (Angle from (Position of (Picked unit)) to (Position of FirstUnit))
You also leak unit groups.

Anything used twice or more should be stored into a variable. The variable should then be used.
This can easily help you stop the trigger from hitting the op-limit.
 
Level 4
Joined
Jan 5, 2014
Messages
79
You also have a ton of leaks.
This leaks a location
  • Set NextPosition = ((Position of (Picked unit)) offset by NewCurrentLenghtOfJump towards (Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) degrees)
This leaks two locations.
  • Set AngleOfKnockbackBeingAdded = (Angle from (Position of (Picked unit)) to (Position of FirstUnit))
You also leak unit groups.

Thanks, I will do something about that (lol, I make sure thing like floating text created on map init doesn't leak a point and forget to do this :goblin_jawdrop: )
 
Status
Not open for further replies.
Top