[Trigger] "call DestroyGroup" stops Unit Group function from working

Level 11
Joined
Mar 18, 2009
Messages
793
Hello! I recently picked up warcraft 3 again and I got stuck on trying to optomize this trigger.
After I added the last line, "Custom script: call DestroyGroup(udg_CapGrp1)" the trigger's main function stops working. I tried repositioning it but from what I can tell it seems to be in the right place but Im not sure?

Also in short, this trigger is supposed to check and manage (partof) a point capture system revolving around Circle of Power buildings placed around the map. I'm trying to keep things simple, and feedback is very much appreciated!

  • CaptureNe Test
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Game - Display to (All players) the text: test
      • Set VariableSet CapGrp1 = CapGrpNeutral
      • Unit Group - Pick every unit in CapGrp1 and do (Actions)
        • Loop - Actions
          • Set VariableSet CapPick = (Picked unit)
          • Set VariableSet CapPos = (Position of CapPick)
          • Set VariableSet CapPlayer = Neutral Passive
          • Set VariableSet CapNumber[13] = 0
          • Set VariableSet CapNumber[1] = 0
          • Set VariableSet CapNumber[2] = 0
          • Set VariableSet CapNumber[3] = 0
          • Set VariableSet CapNumber[4] = 0
          • Set VariableSet CapNumber[5] = 0
          • Set VariableSet CapNumber[6] = 0
          • Set VariableSet CapGrp2 = (Units within 512.00 of CapPos.)
          • Unit Group - Pick every unit in CapGrp2 and do (Actions)
            • Loop - Actions
              • Set VariableSet CapPicked = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of CapPicked) Equal to Neutral Hostile
                • Then - Actions
                  • Set VariableSet CapNumber[13] = 2
                  • Game - Display to (All players) the text: NHostile in place
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of CapPicked) Equal to Player 1 (Red)
                • Then - Actions
                  • Set VariableSet CapNumber[1] = 1
                  • Set VariableSet CapPlayer = Player 1 (Red)
                  • Game - Display to (All players) the text: Capturing
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of CapPicked) Equal to Player 2 (Blue)
                • Then - Actions
                  • Set VariableSet CapNumber[2] = 1
                  • Set VariableSet CapPlayer = Player 2 (Blue)
                  • Game - Display to (All players) the text: Capturing
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of CapPicked) Equal to Player 3 (Teal)
                • Then - Actions
                  • Set VariableSet CapNumber[3] = 1
                  • Set VariableSet CapPlayer = Player 3 (Teal)
                  • Game - Display to (All players) the text: Capturing
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of CapPicked) Equal to Player 4 (Purple)
                • Then - Actions
                  • Set VariableSet CapNumber[4] = 1
                  • Set VariableSet CapPlayer = Player 4 (Purple)
                  • Game - Display to (All players) the text: Capturing
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of CapPicked) Equal to Player 5 (Yellow)
                • Then - Actions
                  • Set VariableSet CapNumber[5] = 1
                  • Set VariableSet CapPlayer = Player 5 (Yellow)
                  • Game - Display to (All players) the text: Capturing
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of CapPicked) Equal to Player 6 (Orange)
                • Then - Actions
                  • Set VariableSet CapNumber[6] = 1
                  • Set VariableSet CapPlayer = Player 6 (Orange)
                  • Game - Display to (All players) the text: Capturing
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (CapNumber[1] + (CapNumber[2] + (CapNumber[3] + (CapNumber[4] + (CapNumber[5] + (CapNumber[6] + CapNumber[13])))))) Equal to 1
            • Then - Actions
              • Game - Display to (All players) the text: Point captured!
              • Unit - Change ownership of CapPick to CapPlayer and Change color
              • Unit Group - Remove CapPick from CapGrpNeutral.
              • Unit Group - Add CapPick to CapGrpP1[(Player number of CapPlayer)]
            • Else - Actions
          • Custom script: call RemoveLocation(udg_CapPos)
          • Custom script: call DestroyGroup(udg_CapGrp2)
      • Custom script: call DestroyGroup(udg_CapGrp1)
 

Rheiko

Spell Reviewer
Level 26
Joined
Aug 27, 2013
Messages
4,214
You're not supposed to destroy it. Essentially, what you're doing is you're making CapGrp1 point to the same group object in memory as CapGrpNeutral. So when you destroy CapGrp1, you're destroying the actual group object in memory and all the variables that were pointing to it (CapGrpNeutral) now reference something that no longer exists. That's why it stops working.

If it's something that you will use over and over again, there is no need to destroy it.

what's the purpose of CapGrpNeutral?
 
Level 11
Joined
Mar 18, 2009
Messages
793
what's the purpose of CapGrpNeutral?
Ahh I see, that explains a lot actually. As you can see this trigger will repeat itself over the course of the game so I'll just leave it as it is then. Thank you for explaining it! :goblin_yeah:

"CapGrpNeutral" is the group where all the uncontested capture points are stored in, its in pair with "CapGrpP1[]" where all the player capture points are stored in.
 

Rheiko

Spell Reviewer
Level 26
Joined
Aug 27, 2013
Messages
4,214
"CapGrpNeutral" is the group where all the uncontested capture points are stored in, its in pair with "CapGrpP1[]" where all the player capture points are stored in.
I see, then there is no reason to destroy it. :peasant-cheers-back:
Also, you can access CapGrpNeutral right away instead of storing it into CapGrp1 first.
 
Level 11
Joined
Mar 18, 2009
Messages
793
I see, then there is no reason to destroy it. :peasant-cheers-back:
Also, you can access CapGrpNeutral right away instead of storing it into CapGrp1 first.
So I ended up remaking the trigger(s) in to one single trigger, and as you said I now access the unit group directly, thank you for the suggestion!
Code seem to work fine for now so I guess the issue has been solved :)

  • Capture Point
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in CapGrp and do (Actions)
        • Loop - Actions
          • Set VariableSet CapPick = (Picked unit)
          • Set VariableSet CapPos = (Position of CapPick)
          • Set VariableSet CapPlayer = Neutral Passive
          • Set VariableSet CapNumber[13] = 0
          • Set VariableSet CapNumber[1] = 0
          • Set VariableSet CapNumber[2] = 0
          • Set VariableSet CapNumber[3] = 0
          • Set VariableSet CapNumber[4] = 0
          • Set VariableSet CapNumber[5] = 0
          • Set VariableSet CapNumber[6] = 0
          • Set VariableSet CapGrp2 = (Units within 350.00 of CapPos.)
          • Unit Group - Pick every unit in CapGrp2 and do (Actions)
            • Loop - Actions
              • Set VariableSet CapPicked = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (CapPicked is A ground unit) Equal to True
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Owner of CapPicked) Equal to Neutral Hostile
                    • Then - Actions
                      • Set VariableSet CapNumber[13] = 2
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Owner of CapPicked) Equal to Player 1 (Red)
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of CapPick) Equal to Player 1 (Red)
                        • Then - Actions
                          • Set VariableSet CapNumber[1] = 2
                        • Else - Actions
                          • Set VariableSet CapNumber[1] = 1
                          • Set VariableSet CapPlayer = Player 1 (Red)
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Owner of CapPicked) Equal to Player 2 (Blue)
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of CapPick) Equal to Player 2 (Blue)
                        • Then - Actions
                          • Set VariableSet CapNumber[2] = 2
                        • Else - Actions
                          • Set VariableSet CapNumber[2] = 1
                          • Set VariableSet CapPlayer = Player 2 (Blue)
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Owner of CapPicked) Equal to Player 3 (Teal)
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of CapPick) Equal to Player 3 (Teal)
                        • Then - Actions
                          • Set VariableSet CapNumber[3] = 2
                        • Else - Actions
                          • Set VariableSet CapNumber[3] = 1
                          • Set VariableSet CapPlayer = Player 3 (Teal)
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Owner of CapPicked) Equal to Player 4 (Purple)
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of CapPick) Equal to Player 4 (Purple)
                        • Then - Actions
                          • Set VariableSet CapNumber[4] = 2
                        • Else - Actions
                          • Set VariableSet CapNumber[4] = 1
                          • Set VariableSet CapPlayer = Player 4 (Purple)
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Owner of CapPicked) Equal to Player 5 (Yellow)
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of CapPick) Equal to Player 5 (Yellow)
                        • Then - Actions
                          • Set VariableSet CapNumber[5] = 2
                        • Else - Actions
                          • Set VariableSet CapNumber[5] = 1
                          • Set VariableSet CapPlayer = Player 5 (Yellow)
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Owner of CapPicked) Equal to Player 6 (Orange)
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of CapPick) Equal to Player 6 (Orange)
                        • Then - Actions
                          • Set VariableSet CapNumber[6] = 2
                        • Else - Actions
                          • Set VariableSet CapNumber[6] = 1
                          • Set VariableSet CapPlayer = Player 6 (Orange)
                    • Else - Actions
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (CapNumber[1] + (CapNumber[2] + (CapNumber[3] + (CapNumber[4] + (CapNumber[5] + (CapNumber[6] + CapNumber[13])))))) Equal to 1
            • Then - Actions
              • Game - Display to (All players) the text: Point captured!
              • Unit - Change ownership of CapPick to CapPlayer and Change color
            • Else - Actions
          • Custom script: call RemoveLocation(udg_CapPos)
          • Custom script: call DestroyGroup(udg_CapGrp2)
 
Top