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

For each integer in A from X to Y...

Status
Not open for further replies.
Level 7
Joined
Jul 29, 2007
Messages
172
Can anyone please explain the whole trigger's functions for me please. This thing had been a question in my mind since a long time ago.

If possible please show me some examples, thanks alot.

P.S Rep will surely be added to those who help. I promise.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
  • For Each integer A from X to Y do
    • Loop - Actions
      • Action 1
      • Action 2
      • ...
It's not Integer IN A. It's Integer A. Integer A acts like an integer variable (and you'll also notice there's an action called "For Each Integer Variable", which basically allows you to REPLACE "A" by any integer you made).
What happens is this:

Set A = X
While A < Y Do:
Actions 1
Actions 2
...
Set A = A + 1

In other words: it'll do all actions AND increase A by 1 as long as A is less than Y.

For example:
  • For each integer A from 1 to 10 do:
    • Loop - Actions
      • Unit - create 1 Footman for player 1 at center of map
Then you'll be creating 10 footmen. Basically: it'll be looping all actions inside the loop for Y - X + 1 times.
Know that you can use the current value of Integer A (which - in this case will be 1, 2, 3, ..., or 10) IN the loop actions. For instance: you can set (Last created unit)'s HP to "Integer A". In this case: you'll be spawning a footman with 1 HP, then one with 2HP, then one with 3 HP, etc.

Notice that you can actually manipulate this action. Let's say you want to damage a certain unit on the map for 10 damage every second as long as the unit's HP is greater than 50%.
Normally, in GUI there's no way you can do this. However: if you do this:
  • For each Integer (MyIntegerVariable!) from 1 to 2 do:
    • Loop - Actions
      • If (all conditions are true) then do (then actions) else do (else actions)
        • If - Conditions
          • Current HP of MyUnit > 50%
        • Then - Actions
          • Set HP of MyUnit = HP of MyUnit - 10
          • Set MyIntegerVariable = 0
          • Wait 1.00 seconds
        • Else - Actions
          • Set MyIntegerVariable = 2
What happens here is: as long as the HP is larger than 50%, MyIntegerVariable (used in the loop) will be set to 0. In other words: it'll NEVER reach the value 2, and thus NEVER stop looping.
As soon as the HP is less than 50%, MyIntegerVariable will be set to 2, and the loop will stop.
 
Status
Not open for further replies.
Top