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

Status
Not open for further replies.

#### Lucianus

Level 7
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.

#### Eleandor

Level 21
• 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.

#### Lucianus

Level 7
Thanks for you help mate. +rep =)

Status
Not open for further replies.

Replies
1
Views
919
Replies
6
Views
2K
Replies
9
Views
929
Replies
3
Views
767
Replies
2
Views
597