• 🏆 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!

[General] loop only running one time

Status
Not open for further replies.
Level 2
Joined
Apr 4, 2020
Messages
16
I am trying to tell every barracks owned my a certain player to train a footman / add a new footman to the training queue every two seconds so I created two triggers to work together:
1) Populate the unit group 'enemybarracks' with all of player 21's barracks and then
  • set variable enemybarracks
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Picked unit)) Equal to Player 21 (Coal)
              • (Unit-type of (Picked unit)) Equal to Barracks
            • Then - Actions
              • Game - Display to (All players) the text: barracks added to '...
              • Unit Group - Add (Picked unit) to enemybarracks
            • Else - Actions
2) tell each barracks in 'enemybarracks' to train a footmen or add a new footmen to it's training queue every two seconds
  • tell all enemybarracks to train footmen every 2 seconds
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in enemybarracks and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to train/upgrade to a Footman
The second trigger only works one time then it tells just one barracks from the group to train a footman. The trigger does tell every barracks in the unit group to train ONE footman the first time (like it is supposed to do), but then the trigger never correctly fires again. Why does my looped trigger stop working and only tell one unit in the group to train a footman after one iteration?
 
Last edited:
Level 28
Joined
Feb 18, 2014
Messages
3,580
First of all make sure the player has enough resources and food. Secondly, you are leaking a unit group and the first trigger is pointless since you can do everything inside one trigger.
  • Train Footman Loop
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Owner of (Matching unit)) Equal to Player 21 (Coal)) and ((Unit-type of (Matching unit)) Equal to Barracks))) and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to train/upgrade to a Footman
 
Level 6
Joined
Dec 31, 2017
Messages
138
What happens when
  • Game - Display to (All players) the text: (String((Number of units in enemybarracks)))
is added to "
base.gif
tell all enemybarracks to train footmen every 2 seconds"? Does it print the correct number?
 
Status
Not open for further replies.
Top