ItsMods

Full Version: Basic GSC Coding: For
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello

This is the third tutorial about basic GSC coding, this time is about the "for" command. Its use is nearly the same as the "while", it repeats something until you stop it and with a frequency you add, its "basic" structure is the following:

Code:
for( ; ; )
{
    CODES
    wait ( TIME );
}

You can add "break"s or "endon"s like in "while" command to destroy the "for"s. The advantage of the "for" in relation to the "while" is that you can make it repeat a certain ammount of times in less space than a "while":

Code:
for( index = 0; index <= 10; index ++ )
{
    CODES
    wait ( TIME );
}

I called a variable "index", you can call it however you want, examples:

Code:
for( i = 0; i <= 10; i ++ )
for( fortutorial = 0; fortutorial <= 20; fortutorial ++ )
for( j = 0; j <= 20; j ++ )
for( dollar = 0; dollar <= 15; dollar ++ )

The first place inside the ( ) is the number with the one the variable starts, the second place is the repetition when the "for" ends ( in my example it will end at 10 repetitions) and the third place is how the variable value changes after each repetition. What I have put: "index ++", does that the value of the index increases in 1 in each repetition. To change numbers, the most common operators are the following ones (there are more, but they arent that basic):

Code:
index += NUMBER (it will add the number you put there)
index ++ (it is the same as doing index += 1, its shorter)
index -= NUMBER (it will decrease the variable number in the ammount of units you put on "NUMBER")
index -- (it is the same as doing index -= 1, its shorter)
index *= NUMBER (multiplication of the value * the number)
index /= NUMBER (division of the value / the number)

When inside a "for" there is just 1 line of code and the wait is not needed, you can remove the "{" and the "}". Example:

Code:
for( g = 0; g <= 4; g ++ )
{
    self waittill( "killed_player" );
}

You can reduce it to (this example does that it repeats after each time you killed an enemy):

Code:
for( g = 0; g <= 4; g ++ )
    self waittill( "killed_player" );

I hope you liked this 3rd tutorial, any question or problem, just reply to this thread.

Thanks, @Yamato
I know how they work, yet I found this tutorial confusing to read.
(03-02-2012, 16:24)AZUMIKKEL Wrote: [ -> ]I know how they work, yet I found this tutorial confusing to read.

My english fails, Undecided
i understod all in this tuto . :p
(03-05-2012, 00:13)alvarogt95 Wrote: [ -> ]i understod all in this tuto . :p

So I did. Good work Yamato! Keep making those basic GSC codindind tuts!