HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Wait in Loops?

12-14-2009, 04:20 AM#1
SmileyJeff
I know that
Trigger:
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Loop - Actions
and
Trigger:
Player Group - Pick every player in (All players) and do (Actions)
Loop - Actions
shouldn't use wait in it.

But what about others? Like:
Trigger:
For each (Integer A) from 1 to 10, do (Actions)
Loop - Actions
Can i use wait in this loop? If so is it recommended or there is a more efficient way to do it?
12-14-2009, 05:02 AM#2
Rising_Dusk
You can use a wait in that loop, but it is more accurate (for low wait periods, < 2s) to use timers instead.
12-14-2009, 11:42 AM#3
Themerion
Dusk...?

Collapse How a for loop looks:

  // These are global variables, no?
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
       // <INSERT YOUR ITERATION-CODE HERE>
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop

I mean, strictly speaking, Dusk is correct. You can do it, but it's really, really setting you up for a lot of trouble (since it will cause other for-loops to screw up, should they run simultaneously).
12-14-2009, 02:06 PM#4
Rising_Dusk
I didn't say that he should, only that he could. In GUI, the 'best' one to use is probably that trigger that internally uses a timer. (Periodic trigger)
12-15-2009, 03:55 PM#5
Themerion
Quote:
I didn't say that he should, only that he could.

So, if somebody asks you if a poison is edible, your response is "yes" (omitting the ", but you'll die from it") ?

Quote:
In GUI, the 'best' one to use is probably that trigger that internally uses a timer. (Periodic trigger)

Agreed. Even if I prefer jass haxx...

Trigger:
Custom Script: local variable counter=0
--- ---
Custom Script: loop
Custom Script: exitwhen counter >= 10
--- ---
Custom Script: counter = counter + 1
Custom Script: endloop
--- ---
12-15-2009, 05:47 PM#6
Kueken
Explanation:
For each integer a loops suffer from the fact, that integer a is a global variable. If you use a wait in such a loop, it will be screwed up by another ForintegerA loop. So if you use waits in those, you should use ForInteger (variable) and only use this variable for this loop (and make sure only one instance of this loop can run at one time).

However, taking a periodic trigger is better in most cases (and more exact, waits have a minimum time of ~0.5 seconds in multiplayer)

or we do zinc hax to save lines :D (does not work that way, though :D)
Trigger:
Custom Script: //! zinc
Custom Script: library bla{function bleh{integer i;for(0<i<=10){DoNothing();}}}
Custom Script: //! endzinc