• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Trigger help Looping

Status
Not open for further replies.
Level 4
Joined
Jul 14, 2012
Messages
100
Ok so basically heres the trigger that doesnt seem to work:

  • a village is conquered
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Dying unit)) Not equal to (Owner of (Killing unit))
      • Or - Any (Conditions) are true
        • Conditions
          • ((Unit-type of (Dying unit)) Equal to Landlord's Dwelling) or ((Unit-type of (Dying unit)) Equal to Chieftan's Hut)
          • (Unit-type of (Dying unit)) Equal to Royal Palace
          • (Unit-type of (Dying unit)) Equal to Imperial Capital
    • Actions
      • Set villageontheline = (Dying unit)
      • For each (Integer A) from 1 to 102, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (village[(Integer A)] is alive) Equal to True
              • (Owner of village[(Integer A)]) Equal to (Owner of (Dying unit))
            • Then - Actions
              • Set villagehappiness[(Integer A)] = (villagehappiness[(Integer A)] - 4)
              • For each (Integer A) from 1 to 102, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (village[(Integer A)] is alive) Equal to True
                      • (Owner of village[(Integer A)]) Equal to (Owner of (Dying unit))
                      • villagehappiness[(Integer A)] Less than or equal to 0
                    • Then - Actions
                      • Game - Display to (All players) the text: (One of + ((Name of (Owner of village[(Integer A)])) + 's villages has revolted!))
                      • Unit - Change ownership of village[(Integer A)] to Player 11 (Dark Green) and Change color
                    • Else - Actions
                      • Do nothing
            • Else - Actions
              • Do nothing
      • Dialog - Show razeorcapture for (Owner of (Killing unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of living Chieftan's Hut units owned by (Owner of (Dying unit))) Equal to 0
          • (Number of living Landlord's Dwelling units owned by (Owner of (Dying unit))) Equal to 0
          • (Number of living Royal Palace units owned by (Owner of (Dying unit))) Equal to 0
          • (Number of living Ancient Settler units owned by (Owner of (Dying unit))) Equal to 0
          • (Number of living Medieval Settler units owned by (Owner of (Dying unit))) Equal to 0
          • (Number of living Renaissance Settler units owned by (Owner of (Dying unit))) Equal to 0
          • (Number of living Imperial Capital units owned by (Owner of (Dying unit))) Equal to 0
        • Then - Actions
          • Game - Display to (All players) the text: A Civilization has ...
        • Else - Actions
          • Do nothing
So in my map, each village has happiness and happiness does update correctly, but for some reason, only 1 village owned by the player of the destroyed city actually loses happiness. The rest are unaffected. Any idea why?
 
Get rid of the 2nd loop :
  • Set villagehappiness[(Integer A)] = (villagehappiness[(Integer A)] - 4)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • villagehappiness[(Integer A)] Less than or equal to 0
    • Then - Actions
      • Game - Display to (All players) the text: (One of + ((Name of (Owner of village[(Integer A)])) + 's villages has revolted!))
      • Unit - Change ownership of village[(Integer A)] to Player 11 (Dark Green) and Change color
The fact is that you are using "Integer A" in both loop. If you ever need to make a loop-in-a-loop trigger, use "Integer B" for the 2nd. But that's useless here.
 
Level 4
Joined
Jul 14, 2012
Messages
100
Get rid of the 2nd loop :
  • Set villagehappiness[(Integer A)] = (villagehappiness[(Integer A)] - 4)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • villagehappiness[(Integer A)] Less than or equal to 0
    • Then - Actions
      • Game - Display to (All players) the text: (One of + ((Name of (Owner of village[(Integer A)])) + 's villages has revolted!))
      • Unit - Change ownership of village[(Integer A)] to Player 11 (Dark Green) and Change color
The fact is that you are using "Integer A" in both loop. If you ever need to make a loop-in-a-loop trigger, use "Integer B" for the 2nd. But that's useless here.

OHH okay! Thanks so much it works now
 
Get rid of the "do nothing" function, it is literally pointless and makes no odds to what happens

Also I notice you run the two loops one within the other, but there's really no need to, it just means if more than one village revolts at the same time, messages will be repeated for each one you could just do this instead:

  • Set villageontheline = (Dying unit)
  • For each (Integer A) from 1 to 102, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (village[(Integer A)] is alive) Equal to True
          • (Owner of village[(Integer A)]) Equal to (Owner of (villageontheline))
        • Then - Actions
          • Set villagehappiness[(Integer A)] = (villagehappiness[(Integer A)] - 4)
  • For each (Integer A) from 1 to 102, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (village[(Integer A)] is alive) Equal to True
          • (Owner of village[(Integer A)]) Equal to (Owner of (villageontheline))
          • villagehappiness[(Integer A)] Less than or equal to 0
        • Then - Actions
          • Game - Display to (All players) the text: (One of + ((Name of (Owner of village[(Integer A)])) + 's villages has revolted!))
          • Unit - Change ownership of village[(Integer A)] to Player 11 (Dark Green) and Change color
          • Else - Actions
 
Status
Not open for further replies.
Top