[Tutorial] How to indent
#1

Introduction

Time to time, we get the occasional "fix my code" or "what must I do" in Scripting Help, fair enough. One issue that tends to arise though, is the unreadable code that the OP may provide.

PAWN is a free format language. There is no strict way of doing things. Whether you may find this as a blessing or not, it allows you to write code in a way that conforms to your style of scripting (and is syntactically correct).

Better yet, it's also structured. We are allowed to section off or hide necessary information to perform specific tasks (subroutines, code-blocks etc.), hence the idea of compartmentalization.

Why indent?

Clustered code tends to become an unmanageable mess. Here on the forums, most people will have a much easier time helping and solving problems with readable code. Trying to find the underlying cause of some error may also become a hassle when there may visibly be one true culprit.

How to indent

Think of a block of code as a group or section that contains the instructions to perform (if not one) multiple tasks. Each block is defined by an opening and closing brace ( { and } ). Every time you define a code-block, the code within that block is indented.

pawn Код:
doSomething()
{
    /*new block of code, indent*/
   
    for(new i = 0; i < 4; i++)
    {
        /*new block of code, indent*/
       
        printf("%d", i);
    }
}
#pragma tabsize 0

People wanting to get rid of the loose indentation warnings generated by the compiler would often use,
pawn Код:
#pragma tabsize 0
Do note that this is NOT a solution, only a workaround.

Quote:
Originally Posted by Wiki
This is set to 4 in SA:MP as that is the size of a tab in pawno. Setting this to 0 will surpress all your indentation warnings but is highly unadvised as it allows entirely unreadable code.
Reply


Messages In This Thread
How to indent - by u3ber - 10.01.2013, 01:10
Re: How to indent - by [HK]Ryder[AN] - 10.01.2013, 03:31
Re: How to indent - by ThePhenix - 10.01.2013, 03:38
Re: How to indent - by zJordioz - 11.01.2013, 22:37
Re: How to indent - by Vince - 11.01.2013, 22:40
Re: How to indent - by JaKe Elite - 12.01.2013, 01:36
Re: How to indent - by u3ber - 12.01.2013, 11:12
Re: How to indent - by [HK]Ryder[AN] - 12.01.2013, 14:28

Forum Jump:


Users browsing this thread: 2 Guest(s)