Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial Basic GSC Coding: For
#1
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
Reply

#2
I know how they work, yet I found this tutorial confusing to read.
YouTube 1:Azumikkel- Modding
YouTube 2:DerpShark- Gaming Entertainment
Website:Jensby.me
Contact: im[at]jensby.me
Reply

#3
(03-02-2012, 16:24)AZUMIKKEL Wrote: I know how they work, yet I found this tutorial confusing to read.

My english fails, Undecided
Reply

#4
i understod all in this tuto . :p
Reply

#5
(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!
[Image: 1nzceg.png]
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tutorial] Basic GSC Coding: Building your first mod and your first code Yamato 2 11,205 06-07-2016, 21:49
Last Post: FrostbytePG
  [Tutorial] Basic GSC Coding: Functions Yamato 15 12,284 08-17-2013, 10:17
Last Post: hamza-q99
  [Tutorial] Basic GSC Coding: Making your second code Yamato 9 8,636 12-28-2012, 13:30
Last Post: Yamato
  [Tutorial] Basic GSC Coding: Operations Yamato 0 8,004 04-04-2012, 13:07
Last Post: Yamato
  [Tutorial] Basic GSC Coding: Foreach, Continue and Return Yamato 6 7,574 04-04-2012, 08:33
Last Post: Yamato
  [Tutorial] Basic GSC Coding: Switch Yamato 6 6,035 04-03-2012, 18:32
Last Post: tsoPANos
  [Tutorial] Basic GSC Coding: If, Else and Else If Yamato 2 5,795 03-30-2012, 10:47
Last Post: alvarogt95
  [Tutorial] Basic GSC Coding: Downloading and Installing a mod Yamato 1 5,195 03-30-2012, 10:42
Last Post: alvarogt95
  [Tutorial] Basic GSC Coding: While, Break and Wait Yamato 6 7,516 03-06-2012, 13:48
Last Post: Yamato

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.