I don't understand Loops

Battle[StFh]

New Member
Reaction score
6
Hey guys,

I've got a problem, and it's a really annoying problem...
I just don't understand Loops...
I'll explain what I don't get:
Code:
For each (Integer A) from 1 to 10, do (Actions)
    Loop - Actions

Ok, I'd really appreciate if someone would be able to explain what the World Editor means with Integer A, and what the "from 1 to 10" means.
There's also a Integer B action:
Code:
For each (Integer B) from 1 to 10, do (Actions)
    Loop - Actions
Well, again... what does that mean?

What's the difference between Integer A and B... Which Integer do you take if you take Integer A?

I'm really confused by these problems :confused: ... :banghead:

Is there anyone that can help me?

Thanks in advance

Battle[StFh]
 
B

Blue_Hand

Guest
loops are used with arrays
for example (it's example from my map)
you have an arrays so you do :
Code:
For each (Integer A) from 1 to Playing_Players_Number, do (Actions)
    Loop - Actions
        Set P_Hungry[(Integer A)] = 0.00
        Set P_Iron[(Integer A)] = 0
        Set P_Kills[(Integer A)] = 0
        Set P_Thirsty[(Integer A)] = 0.00
        Set P_Tired[(Integer A)] = 0.00
        Set Factor_Hunger[(Integer A)] = 1.00
        Set Factor_Thirst[(Integer A)] = 1.00
        Set Factor_Tired[(Integer A)] = 1.00
some things you can't do wihout loop, anyway you save much time using a loop
Interger B is when you want to make loop inside another loop
for example (I know there is simplier way of adding item charges:), this is only exemple ) :
Code:
item Cumulation
    Events
        Unit - A unit owned by Player 1 (Red) Acquires an item
    Conditions
    Actions
        Set item_addiction = (Item-type of (Item being manipulated))
        For each (Integer B) from 1 to 6, do (Actions)
            Loop - Actions
                For each (Integer A) from 0 to ((Integer B) - 1), do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Item-type of (Item carried by (Hero manipulating item) in slot (Integer B))) Equal to item_addiction
                                (Item-type of (Item carried by (Hero manipulating item) in slot (Integer A))) Equal to item_addiction
                            Then - Actions
                                Item - Set charges remaining in (Item carried by (Hero manipulating item) in slot (Integer B)) to ((Charges remaining in (Item carried by (Hero manipulating item) in slot (Integer B))) + (Charges remaining in (Item carried by (Hero manipulating item) in slot (Integer A))))
                                Item - Remove (Item carried by (Hero manipulating item) in slot (Integer A))
                            Else - Actions
                For each (Integer A) from ((Integer B) + 1) to 6, do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Item-type of (Item carried by (Hero manipulating item) in slot (Integer B))) Equal to item_addiction
                                (Item-type of (Item carried by (Hero manipulating item) in slot (Integer A))) Equal to item_addiction
                            Then - Actions
                                Item - Set charges remaining in (Item carried by (Hero manipulating item) in slot (Integer B)) to ((Charges remaining in (Item carried by (Hero manipulating item) in slot (Integer B))) + (Charges remaining in (Item carried by (Hero manipulating item) in slot (Integer A))))
                                Item - Remove (Item carried by (Hero manipulating item) in slot (Integer A))
                            Else - Actions
 

Sooda

Diversity enchants
Reaction score
318
Rofl it explaned alot... Integer A is updated each time when loops run (Loop runs as many times as numbers spesified, if it' s from 1 to 10 it runs 10 times.) And integer A becomes a counter if it is running second time integer A would be 2. Integer B is used for Loop inside loop. It' s like if Intger A loops 10 times and each time you have in actions integer B somewhere then it loops before B times and then continues to next Integer A loop.
Good example is if you use integer A loop from 1 to 12 and give gold to player(Integer A) it gives to each player ammount of gold.
 

Battle[StFh]

New Member
Reaction score
6
Ermm...

I'm lost again :confused:

Wait let me try to tell what it is ...

If you set Integer A from 1 to 3 it runs three times... right?

Then if you do
Code:
Set Max_Thirsty[(Integer A)] = 100
The First time Integer A runs you set Max_Thirsty[1] to 100
The next time it runs you set Max_Thirsty[2] to 100
and the last (third) time it runs you set Max_Thirsty[3] to 100... Right?

So, you just use loops to set Variables?
 
B

Blue_Hand

Guest
yes. it is :D I though that example is the best way of explaining something
 

lh2705

Just another Helper
Reaction score
111
So, you just use loops to set Variables?

Not only variables, loops are used to shorten trigger length.

For example,

Code:
Long

Unit - Create 1 Footman at Centre of Entire Map
Wait 0.20 game-time seconds
Unit - Create 1 Footman at Centre of Entire Map
Wait 0.20 game-time seconds
Unit - Create 1 Footman at Centre of Entire Map
Wait 0.20 game-time seconds
__________________________________________
Shortened

For each (Integer A) from 1 to 3, do (Actions)
    Loop - Actions
      Unit - Create 1 Footman at Centre of Entire Map
      Wait 0.20 game-time seconds

There are many many more things loops can do...
 

SFilip

Gone but not forgotten
Reaction score
634
> loops are used with arrays
And this is where all the confusion starts...
> So, you just use loops to set Variables?
If you at any point need to do something multiple times then you use a loop. And you will need to use it, trust me.
For example take a look at the second trigger in Blue_Hand's post - it roughly picks all items owned by a certain hero.
But yes, certainly the most useful (yet again not only) application for loops is for quickly dealing with arrays.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top