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

What is if-action, and loop-action?

Status
Not open for further replies.

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Yes, they are often needed.
This is in Zinc but it's commonly used in GUI as well:
JASS:
                if(winner.allCounters[i].CostFilter(p))
                {
                    if(winner.allCounters[i].filter != null)
                    {
                        if(filterFunc(winner.allCounters[i].filter))
                        {
                            BJDebugMsg("calling build! 1");
                            Build(p, winner.allCounters[i].unitID);
                            break;
                        }
                        else
                        {
                            BJDebugMsg("requirements were not met.");
                        }
                    }
                    else
                    {
                        BJDebugMsg("calling build! 2");
                        Build(p, winner.allCounters[i].unitID);
                        break;
                    }
                }
                else
                {
                    BJDebugMsg("not enough gold or lumber");
                }
                i += 1;
            }

The usage is waaay to common to give one specific answer of when to use them, they come in handy all the time.

_____________________________

A unit group loops through all units automatically.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
You don't need jass. I just happened to have a good example in jass.

Pick all units in <group>
pause picked unit

edit: there is actually a action that pauses all units without a unit group:
  • Unit - Pause all units
However, for learning purposes you would as I said do:
  • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • Unit - Pause (Picked unit)
 
Level 7
Joined
Oct 19, 2015
Messages
286
Loops are used when you want to repeat the same actions multiple times. Usually, you don't want the actions to be exactly the same, for example you want to run the same code but each time on a different unit. That's why we have different loops, there are unit group loops like mentioned above which repeat the same actions for each unit in a group, then you have integer loops that repeat the same code a certain number of times and use an integer variable to tell the code how many times it has already run.

If statements are used when you want an action to occur only if a condition is true. That way, you can make your code respond to the state of the game, for example you can run different actions if a certain unit is alive than you would if it is dead.
 
Status
Not open for further replies.
Top