ARTICLE
Written by Chronic
Posted on 9/Nov/2006
Version 1.0
Indenting your codePosted on 9/Nov/2006
Version 1.0
When writing a script its good practice to learn to indent your code. This is for many reasons, but the main one is to make it easier to read for yourself and others.
So, what is indenting? I'm sure you've heard of this word before, if not then its basicly putting a tab or a few spaces infront of a line of code. This is normaly done when starting a new block of code. Lets take a look at a few examples of where you could use an indent.
Note, To make it more easier to see, i will be using a point (aka fullstop) instead of space to show an indent.
When starting a program:
: (SCRIPT)
{
..CODE;
}
..CODE;
}
In blocks of code:
: (SCRIPT)
{
..if (statement) {
....CODE;
....CODE;
....if (statment) {
......CODE;
....}
..}
}
..if (statement) {
....CODE;
....CODE;
....if (statment) {
......CODE;
....}
..}
}
In this case i've used 2 spaces to indent, this is what i commonly use when programming. You may have your own preference to how spaces many you use, or you may even want to use tabs to indent with.
Game Maker has an option to auto indent your code, this can make it a lot easier on you if you're just starting to learn to indent. However, you need to actualy place an indent first. Then next time you press enter Game Maker will match the indent of the line above.
So, next time you're asking for help on a script you have a problem with, keep in mind of how clear your script is to read.