Need Help Fixing a Small trigger!

panzer

New Member
Reaction score
0
I have recently made this trigger and i have made a mistake somewhere!
I will tell you what is wrong with it But first let me show you the Trigger

It goes like this:
..............................................................................................
Event:
Every 60 Sec Of the game

Condition:
(Number of living Footman units owned by Player 2 (Blue)) Equal to 0

Action:
Unit Group - Pick every unit in (Units owned by Player 2 (Blue) of type Barracks) and do (Unit Group - Order (Units owned by Player 2 (Blue) of type Barracks) to train a Footman)
..............................................................................................

I want the each barack to train ONLY 1 Footman, But instead what it does, it trains four footman each.

could anyone help me fix this problem please!
Your Help would be greatly Appreciated!
Thanks

P.S Sorry for the bad quality of the attachment, didn't know how to do it properly.
 

Attachments

  • Trigger.jpg
    Trigger.jpg
    84.8 KB · Views: 80

Executor

I see you
Reaction score
57
Trigger:
  • Your Trigger
    • Events
      • Time - Every 60 seconds of gametime
    • Conditions
      • (Number of living Footman units owned by Player 2 (Blue)) Equal to 0
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 2 (Blue) of type Barracks) and do (Unit Group - Order (Units owned by Player 2 (Blue) of type Barracks) to train a Footman)


(you can use rightclick on trigger and "copy as text" then paste it in here and wrap it in [.WC3][./WC3] tags (without . ))

Well, think about it.
You pick every unit of type Barracks owned by Player 2.
This means the code behind the "and do" is executed once per unit picked, also once per unit of type Barracks owned by Player 2.
This means "Order <Picked Unit> to train a Footman" would be enough to issue every building to produce exact one footman, but you issue the UNIT GROUP of all Barracks owned by Player 2 to produce one footman.

Example:
You have 4 Barracks.
Pick every Barrack
Order all Barracks to produce Footman

=>

4x Order all Barracks to produce Footman

4x Footman per Barrack.




So basically the action "Unit Group - Order (Units owned by Player 2 (Blue) of type Barracks) to train a Footman" is enough, you don't need the "pick every unit .."
 

Bogrim

y hello thar
Reaction score
154
What Executor is talking about is that the Unit Group action is much like the "For Each Integer A from 1 to 10" action, it basically creates a loop of actions which repeats itself for each unit in the group.

The difference between the two actions is that each loop in the unit group refers to one of the picked unit, allowing you to perform an action on every single unit in the group.

What panzer's trigger does is this:

- Picks all units of type Barracks, creating an action for each unit in the group (4).

Action for Barrack (1): Sets all Barracks to train a footman.
Action for Barrack (2): Sets all Barracks to train a footman.
Action for Barrack (3): Sets all Barracks to train a footman.
Action for Barrack (4): Sets all Barracks to train a footman.

The problem here is that the action used to train the Footman does not order the invidual unit picked to train a Footman, but all Barracks on the entire map. As a result, he orders all Barracks to train Footmen equal to the number of Barracks.

How the trigger really should look:
Trigger:
  • Spawn
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Footman) and ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Equal to Player 2 (Blue)))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Temp_Group) Equal to 0
        • Then - Actions
          • Custom script: call DestroyGroup( udg_Temp_Group )
        • Else - Actions
          • Custom script: call DestroyGroup( udg_Temp_Group )
          • Set Temp_Group = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Barracks) and ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Equal to Player 2 (Blue)))))
          • Unit Group - Pick every unit in Temp_Group and do (Unit - Order (Picked unit) to train/upgrade to a Footman)
          • Custom script: call DestroyGroup( udg_Temp_Group )

I changed the structure to prevent memory leaks. Whenever you refer to a unit group that's not already a variable, even in a trigger condition, the game automatically creates a variable for the unit group. This automatically created variable can never used again or removed, but will continue to use the game's memory (a leak). By using Custom Scripts you can remove these unnecessary unit groups and reduce the memory your map takes to run.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top