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

Basics - Loops

Status
Not open for further replies.

NEL

NEL

Level 6
Joined
Mar 6, 2017
Messages
113
Part 1

Create a function, that runs on map initialiaztion.
The function's goal is to create <Footman Amount> footmen for Player_1 using a loop.

vJASS:
//! zinc
library Loops {
    private {
        constant integer footmanAmount = 5;
       
        function onInit() {
            integer Count = 0;
           
            while( Count < footmanAmount ) {
                CreateUnit( Player(0), 'hfoo', 0, 0, 0 );
                Count = Count + 1;
            }
        }
    }
}
//! endzinc





Part 2

Insert a new condition to exit the loop from Part 1 -- now the loop should (also) exit if Player_1's currently used food level is above "3".

vJASS:
//! zinc
library Loops {
    private {
        constant integer footmanAmount = 5;
       
        function onInit() {
            integer Count = 0;
           
            while( 
                Count < footmanAmount && 
                GetPlayerState( Player(0), PLAYER_STATE_RESOURCE_FOOD_USED ) <= 3
            ) {
                CreateUnit( Player(0), 'hfoo', 0, 0, 0 );
                Count = Count + 1;
            }
        }
    }
}
//! endzinc





Part 3

Create a new function, that also runs on map initialization.
The function's goal is to loop through all players, and to create <Footman Amount> footmen units for all of the players with using a loop, as well.

vJASS:
//! zinc
library Loops {
    private {
        constant integer footmanAmount = 5;
       
        function createFootmen() {
            integer Count = 0;
            integer Index = 0;
           
            while( Index < bj_MAX_PLAYERS ) {
                while( Count < footmanAmount ) {
                    CreateUnit( Player( Index ), 'hfoo', 0, 0, 0 );
                    Count = Count + 1;
                }
               
                Index = Index + 1;
                Count = 0;
            }
        }
       
        function onInit() {
            integer Count = 0;
           
            while( 
                Count < footmanAmount && 
                GetPlayerState( Player(0), PLAYER_STATE_RESOURCE_FOOD_USED ) <= 3
            ) {
                CreateUnit( Player(0), 'hfoo', 0, 0, 0 );
                Count = Count + 1;
            }
           
            createFootmen();
        }
    }
}
//! endzinc
 

Attachments

  • [Crash Course] Basics - Loops.w3m
    23.9 KB · Views: 75
Status
Not open for further replies.
Top