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

Does this loop work?

Status
Not open for further replies.
Level 7
Joined
Jun 23, 2009
Messages
297
So I know loops have been around for quite a while, but I never really understood them. Today I decided it's about time, so I made my first loop.
I want to set every player (there are 10 players) current lumber and gold to 0

  • For each (Integer A) from 1 to 10, do (Player - Set (Player(((Player number of Player 1 (Red)) + 1))) Current gold to 0)
Does it work?


And in a completely unrelated topic, what the f**k is MUI and MPI? I read these initials everywhere, I tried searching for it, it seems everybody was born knowing what they stands for.
 
Level 11
Joined
Oct 13, 2005
Messages
233
So I know loops have been around for quite a while, but I never really understood them. Today I decided it's about time, so I made my first loop.
I want to set every player (there are 10 players) current lumber and gold to 0

  • For each (Integer A) from 1 to 10, do (Player - Set (Player(((Player number of Player 1 (Red)) + 1))) Current gold to 0)
Does it work?

Not exactly. That will set the gold for player2 to 0, 10 times. Instead, you want the loop to look something like this:
Code:
For each (integer a) from 1 to 10 do:
Player - Set Player(Integer A) current gold to 0

And in a completely unrelated topic, what the f**k is MUI and MPI? I read these initials everywhere, I tried searching for it, it seems everybody was born knowing what they stands for.
If a trigger is MUI, it means that trigger will work no matter how many units/player/etc are using it at once. Ideally, all necessary triggers in a map would be MUI if they need to be (such as triggered spells).

MPI means that the trigger is able to be used by every player at the same time, but not multiple times at once by the same player.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Loops in WC3 work like this.

Code:
loop
exitwhen [boolean]
endloop

Where [boolean] is a variable or statement which generates a boolean value (usually a condition).

The code inbetween loop and endloop will be repeated infinatly until an exitwhen statement is given a true boolean value or a thread crash occurs. Loops may use more than 1 exitwhen statement to break out from many points within the looping code.

Some uses people often forget about.
Code:
exitwhen false //completly redundant waste of time line, never use
exitwhen true //will always terminate the loop (breaks out of loop)


A thread crash may occur on some invalid parameters (division by 0 or passing stupid values to natives) or when the op limit is exceeded (too many instructions are executed without some pause).

The crappy for loop actions that GUI use are constructed from the above structure. Idealy you want to difine your own looping structure as it allows for more flexibility with your code flow and can increase efficency.
 
Status
Not open for further replies.
Top