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:
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":
I called a variable "index", you can call it however you want, examples:
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):
When inside a "for" there is just 1 line of code and the wait is not needed, you can remove the "{" and the "}". Example:
You can reduce it to (this example does that it repeats after each time you killed an enemy):
I hope you liked this 3rd tutorial, any question or problem, just reply to this thread.
Thanks, @Yamato
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